Forum: Ruby How to refresh a page on browser using selenium-webdriver.

Posted by Love U Ruby (my-ruby)
on 2013-01-24 15:08
Follow the below part of the code:

driver.get "https://example.com/"

element = driver.find_element :name => "username"
element.send_keys "*****"
element = driver.find_element :name => "password"
element.send_keys "*****"
element.submit

Now point is when the "driver" opened the URL on the browser, Some times
the next page to which username and password has to be put by the
script, not coming- which causes the script to failed. Some intermediate
page is coming asking us to click on 'retry button' or 'refresh the
page'. Thus the script whenever such case occurred stopped execution, as
not getting the mentioned element.


So is there any way to refresh that intermediate page with "sleep"
before going to the "Log-in" page, so that script can run in one go?

Thanks,
Posted by Joel Pearson (virtuoso)
on 2013-01-24 16:28
Refresh a page:
driver.get driver.url

Waiting:

http://seleniumhq.org/docs/04_webdriver_advanced.j...

Something like this:
_____________________________

tried = false

begin

  driver.get "https://example.com/"
  wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
  element = wait.until { driver.find_element(:name => "username") }
  element.send_keys "*****"
  element = driver.find_element :name => "password"
  element.send_keys "*****"
  element.submit

rescue => Timeout

  fail if tried
  tried = true
  retry

end
Posted by Love U Ruby (my-ruby)
on 2013-01-24 16:42
Joel Pearson wrote in post #1093536:
> Refresh a page:
> driver.get driver.url
>
> Waiting:
>
> http://seleniumhq.org/docs/04_webdriver_advanced.j...
>
> Something like this:
> _____________________________
>
> tried = false
>
> begin
>
>   driver.get "https://example.com/"
>   wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
>   element = wait.until { driver.find_element(:name => "username") }
>   element.send_keys "*****"
>   element = driver.find_element :name => "password"
>   element.send_keys "*****"
>   element.submit

Yes,But the username will never come,unless the intermediate page not 
getting refreshed. But it is happening 4 times out of 10.

is "driver.url" fetching the "current url" or what?
Posted by Joel Pearson (virtuoso)
on 2013-01-24 17:24
driver.url is the current url, so it effectively refreshes the page.

You can obviously customise my example to loop as many times as you 
like, but I'd recommend avoiding infinite loops.
The "refresh" should not be necessary because the first line executed on 
a retry is
driver.get "https://example.com/"
thus negating the need to refresh the page.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.