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?
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.
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.
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.
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.
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 :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With