Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wait until page refreshed

Here is a description of what I am trying to do using Selenium Webdriver in Python: I have my website which takes as input various parameters for a specific product and outputs a price for the product with those parameters. I am keeping all but one parameters constant and varying one specific parameter in a for loop to see how the price varies according to that one specific parameter. Once i change the parameter i submit the form and then i use implicitly wait as follows:

submit_btn.click()
driver.implicitly_wait(10)  
driver.find_element_by_name("Buy_Product")
soup=BeautifulSoup(driver.page_source)

When entering the first set of parameters the page is clear and it does not contain the buttton with name "Buy_Product" so i am using the line

driver.find_element_by_name("Buy_Product")

to make sure the code waits for that button to appear which will mean the page now contains the price i want to extract. The problem is that the second time through the loop when i vary the parameter and try to get the new price the button "Buy_Product" is already there so implicitly wait does not work anymore and sometimes it will take the previous page_source before the price has time to be updated. The tricky part is that sometimes even for different parameters the price is the same so i can not just check whether the visible text of the price has changed. Any ideas how this can be solved without using time.sleep?

like image 301
luckyfool Avatar asked Dec 05 '12 14:12

luckyfool


People also ask

How will you wait until a Web page has been loaded completely?

We can wait until the page is completely loaded in Selenium webdriver by using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method. We have to pass return document.

How do I make Selenium wait until page loads?

Using Implicit Wait Let's say a website under test takes ten seconds to load a page until a particular element shows up. In that case, set implicit wait for 10 seconds. The test will pause, and once the time passes, Webdriver will continue to run the script as planned.

How can I tell if Selenium site is refreshed?

UPDATE: Page refresh can also easily be verified if there is some textbox element present. Simply use type command to insert some text into the textbox field, then refresh the page, and the text inside textbox should return to it's original state.

Which wait command will wait indefinitely for page load?

PageLoadTimeout Command This command establishes the time WebDriver must wait for a page to completely load before triggering an error. In case the timeout set is negative, the page load time can be indefinite.


1 Answers

The situation is something tricky here...i'm not sure...if this helps...but give a try...

My suggestion is on JavaScript injection, where i check if the Page is loaded completely and it waits till then. (c# code snippet)

IWait<IWebDriver> Driver_Wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
Driver_Wait.Until(Driver => ((IJavaScriptExecutor)JS_Driver).ExecuteScript("return document.readyState").Equals("complete"));

I hope this helps....All the Best :-)

like image 158
Anuragh27crony Avatar answered Sep 19 '22 08:09

Anuragh27crony