Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WebDriverWait
#1
I want my script repeatedly to check for the existence of some element on a fully loaded page and
return only when that element exists.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC  
import time
options = Options()
options.add_argument("--headless")
caps = webdriver.DesiredCapabilities().FIREFOX
caps["marionette"] = True
browser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"geckodriver.exe")
browser.get("http://pythonscraping.com/pages/javascript/ajaxDemo.html")
try:
	element = WebDriverWait(browser, 10).until(EC.presence_of_element_located(By.ID, "loadedButton"))
finally:
	print(browser.find_element_by_id("content").text)
	browser.close()
Error:
Traceback (most recent call last): File "C:\Python36\kodovi\wbp.py", line 184, in <module> element = WebDriverWait(browser, 10).until(EC.presence_of_element_located(By .ID, "loadedButton")) TypeError: __init__() takes 2 positional arguments but 3 were given
What am I doing wrong?
Reply
#2
you have 'By .ID...'
isn't it BY ID? (no dot)
Reply
#3
Missing a couple of ().
element = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, "loadedButton")))
Reply
#4
snippsat, correct. Thank you, although I don't understand why do we need double brackets.

Larz, By.ID is correct. it's called Locator.
Reply
#5
I use it, senior moment.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverWait improved function euras 0 1,467 Jun-02-2021, 01:40 PM
Last Post: euras
  WebDriverWait visibility isnt defined gr3yali3n 0 1,450 Oct-26-2020, 02:54 AM
Last Post: gr3yali3n

Forum Jump:

User Panel Messages

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