Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh a page on browser using selenium-webdriver?

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?

like image 992
CodeLover Avatar asked Jan 24 '13 19:01

CodeLover


People also ask

What are the ways to refresh a browser using Selenium Webdriver?

Create a webdriver (here chromedriver for chrome browser). Build a new window of chrome using the chromedriver. Navigate to geeksforgeeks website using the get method. Refresh the page using refresh method.

Can we refresh page using Selenium?

The refresh() method is used to refresh the currrent page in selenium.

What is refresh command in Selenium?

Refresh () - Selenium IDE command Refresh reloads the currently loaded page.


2 Answers

For Capybara, I think Tommyixi's comment is the best:

 visit current_path 
like image 112
Percy Avatar answered Sep 25 '22 13:09

Percy


As mentioned in a comment by @Nakilon, with non-Poltergeist drivers in Capybara use the following to refresh the current page:

page.driver.browser.navigate.refresh 

But for a universal fix, use:

page.evaluate_script 'window.location.reload()' 
like image 39
Dan Kohn Avatar answered Sep 24 '22 13:09

Dan Kohn