9

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?

4

2 回答 2

1

如果 Anuragh27crony 的解决方案对您不起作用,您可能还想考虑等待 jquery 处于非活动状态。代码看起来基本相同,但传入这个 javascript 调用:

ExecuteScript("return jQuery.active == 0")
于 2013-01-31T00:07:53.060 回答
1

这里的情况有些棘手......我不确定......如果这有帮助......但试一试......

我的建议是关于 JavaScript 注入,我在其中检查页面是否已完全加载并等到那时。(c# 代码片段)

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"));

我希望这会有所帮助....一切顺利:-)

于 2012-12-06T06:35:20.007 回答