Reputation: 303
I have a problem in my framework that instead of using static sleeps I try to wait for a visibility of an element. The thing is that visibilty of element checks the presence of an element on the DOM, that will return true but in my system the page is not fully loaded yet. What happens is that as soon as I get true when checking the visibility of element I set values. These values get reset when the actual page get fully loaded.
My question is what can I use instead of static sleeps to wait for the actual page (not only the DOM) to get fully loaded as visibility of element is not working for me?
P.S. I'm using Selenium webdriver with python 2.7
/Adam
Upvotes: 2
Views: 5098
Reputation: 4162
Try ExpectedConditions.elementToBeClickable
.
See: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#elementToBeClickable-org.openqa.selenium.By-
Upvotes: 1
Reputation: 862
The expected_conditions.visibility_of_element_located(locator)
method will check for both - the presence of the element in the DOM, and its visibility (element is displayed with height and width greater than zero).
Ideally, the driver.get(url)
method should automatically wait for the full page to be loaded before moving on to the next line. However, this might not behave as expected, in case, the web application being tested uses ajax calls/actions (as although the page has loaded but the ajax actions are still in progress). In such scenario, we can use something like below to wait for stability before performing action(s) on the desired webelements.
# create the firefox driver
driver = webdriver.Firefox()
# navigate to the app url
driver.get('http://www.google.com')
# keep a watch on jQuery 'active' attribute
WebDriverWait(driver, 10).until(lambda s: s.execute_script("return jQuery.active == 0"))
# page should be stable enough now, and we can perform desired actions
elem = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.ID, 'id')))
elem.send_keys('some text')
Hope this helps..
Upvotes: 4