I was actually trying to write a script which will delete the files from 
the webpage. But when I clicked on the delete button,one alert window is 
coming to confirm finally before deletion.

So to handle this I wrote a code as below:

Part - I

alrt = Selenium::WebDriver::TargetLocator.new(driver).alert
alrt.accept

But then I was continually getting an error as below :

D:\Rubyscript\My ruby learning days\Scripts>W9_File_delete.rb
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdr
iver/common/alert.rb:9:in `initialize': undefined method `getAlertText' 
for #<Se
lenium::WebDriver::Driver:0x..fa546df06 browser=:firefox> 
(NoMethodError)
        from 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/s
elenium/webdriver/common/target_locator.rb:76:in `new'
        from 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/s
elenium/webdriver/common/target_locator.rb:76:in `alert'
        from D:/Rubyscript/My ruby learning 
days/Scripts/W9_File_delete.rb:114:i
n `<main>'

Now doing after too much research here : 
http://www.rubydoc.info/gems/selenium-webdriver/frames

Finally I wrote the below :

part - II
driver.switch_to.alert.accept

and it works.

But If I followed the documentation I got the below:

#switch_to ~~>

----------------------------------------------------------
# File 'lib/selenium/webdriver/common/driver.rb', line 92

def switch_to
  @switch_to ||= WebDriver::TargetLocator.new(bridge)
end
-----------------------------------------------------------

Which is the same I did to get an object of `TargetLocator` in part - I. 
then on that object I called `alert` to create `Alert` object and then 
finally `accept` using `Alert` object.

Now my question is Why part - I has failed?

What was the wrong with my code ?

Although I fixed my code,but as for knowledge purpose I think should 
know the wrong.

Could anyone help me on that context?

-- 
Posted via http://www.ruby-forum.com/.