Controlling Selenium using Python - unable to use 'waits'
We maintain a library used by test scripts which do system level testing. Part of the system under test is a website, and to navigate and interact with the website we use JPype to control Selenium 2.0's webdriver. Selenium 2.0 has a Java and C# interface, and for the time being we can't rewrite out test library using either Java or C#, which is why we use JPype to control it. This system was built by someone who recently left the company, and I'm coming up to speed on it now.
Whenever we interact with the website, we're using time.sleeps:
self.browserDict['Driver'].findElement(self.browserDict['By'].id(byId)).click()
time.sleep(_AJAX_TIMEOUT)
>>> self.browserDict['Driver']
<jpype._jclass.org.openqa.selenium.firefox.FirefoxDriver object at 0x0626DD30>
>>> byId
'login_submit'
Any time we click no something, there is a time.sleep() to wait for the next page to load. We have a lot of AJAX, but it seems like there should be a way to wait for AJAX to finish loading. Before he left, the author of this tool explained that there's an issue with either JPype or Selenium that prevents this. So far I can't find this issue, but开发者_如何学运维 I also don't know the wait command that would be used here.
Edit:
One option would be to use implicitlyWait, under the assumption that if the timeout were 6 seconds, it would return immediately after finding an element, however it seems to always wait the full 6 seconds when loading a page.Edit2:
Python bindings directly to selenium 2.0 are now out, however there appears to be no way to wait for Ajax loads to finish with that library either: time.sleep(0.2) # Let the page load, will be added to the AP
(from their example).
Maybe http://wiki.openqa.org/display/SEL/waitForCondition can satisfy your criteria?
ImplicitlyWait through JPype and the Java bindings works, and can fulfill the required need here.
精彩评论