luckyfool
luckyfool

Reputation: 1843

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?

Upvotes: 9

Views: 1827

Answers (2)

Michiel Bugher
Michiel Bugher

Reputation: 1065

If Anuragh27crony's solution doesn't work for you, you may also want to think about waiting for jquery to be inactive. The code will look mostly the same, but pass in this javascript call instead:

ExecuteScript("return jQuery.active == 0")

Upvotes: 1

Anuragh27crony
Anuragh27crony

Reputation: 2957

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 :-)

Upvotes: 1

Related Questions