Python Forum
selenium.wait_for_condition equivalent in Python bindings for WebDriver
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
selenium.wait_for_condition equivalent in Python bindings for WebDriver
#1
Currently, it isn’t possible to use wait for condition Currently it isn’t possible to use wait_for_condition with WebDriver. The python selenium code does provide the DrivenSelenium class for accessing the old selenium methods, but it can’t do wait_for_condition. The selenium wild has some info on that.
Your best bet is to use the WebDriverWait class. This is a helper class that periodically executes a function waiting for it to return True. My general usage is
Skip code block
driver = webdriver.Firefox()
driver.get(‘https://example.com’)
add = driver.find_element_by id(“ajax_button”)
add. click() source = driver.page_source
def compare_source(driver):
try:
return source != driver.page_source
except WebDriverException:
pass
WebDriverWait(driver, 5).until(compare_source)
# and now do some assertions
This solution is by no means ideal.. The try/except is necessary for situations where the page request/response cycle is delayed waiting for some ajax activity to complete.
If compare_source get’s called in the midst of the request/response cycle it’ll throw a WebDriverException. The test coverage for WebDriverWait is also helpful to look at.
Reply
#2
have you tried waiting for an element that is only located on the loaded page?
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
...
WebDriverWait(driverr, 5).until(EC.presence_of_element_located((By.ID,"IDName")))
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 1,263 Apr-20-2023, 05:27 PM
Last Post: farshid
  Problem with Selenium webdriver Fred 1 2,050 Jan-10-2022, 05:45 PM
Last Post: Larz60+
  How do I iterate over an array and perform actions using selenium chrome webdriver? master 0 2,443 Sep-14-2020, 05:28 AM
Last Post: master
  Which webdriver is required for selenium in Pydroid App Rahatt 1 6,336 Jul-31-2020, 01:39 AM
Last Post: Larz60+
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 3,832 Jun-07-2020, 04:42 PM
Last Post: samlee916
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 2,031 May-02-2020, 11:21 AM
Last Post: rajeev1729
  Selenium webdriver error WiPi 4 12,146 Feb-09-2020, 11:38 AM
Last Post: WiPi
  Can not point to Selenium Webdriver path for Python Jupyter Notebook on Azure dadadance 4 10,091 Jul-31-2019, 10:00 PM
Last Post: perfringo
  Selenium Webdriver Memory Problem? satbir129 2 6,896 Mar-01-2019, 04:17 AM
Last Post: satbir129
  Selenium Webdriver Automate gahhon 1 2,875 Feb-19-2019, 04:59 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020