I'm having trouble on figuring out how to use Selenium's wait function. What I'm trying to do is check to see if a element is present and if it is then it'll print a statement. Here is my code:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
browser = webdriver.Firefox()
browser.get("http://google.com")
delay = 3 # seconds
try:
WebDriverWait(browser, delay).until(EC.presence_of_element_located(browser.find_element_by_xpath('//*[@id="hplogo"]')))
print ("Page is ready!")
except TimeoutException:
print ("Loading took too much time!")
The current code gives me the following errors:
Traceback (most recent call last):
File "/Users/John/Documents/waitTest.py", line 10, in <module>
WebDriverWait(browser, delay).until(EC.presence_of_element_located(browser.find_element_by_xpath('//*[@id="hplogo"]')))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/support/wait.py", line 71, in until
value = method(self._driver)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/support/expected_conditions.py", line 59, in __call__
return _find_element(driver, self.locator)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/support/expected_conditions.py", line 274, in _find_element
return driver.find_element(*by)
TypeError: find_element() argument after * must be a sequence, not WebElement
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…