Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.3k views
in Technique[技术] by (71.8m points)

python - __init__() takes 2 positional arguments but 3 were given trying to wait for an element using presence_of_element_located()

The log throw me this :

element.until(EC.presence_of_element_located(By.XPATH("//*[@id='menu-item-9145']/a'")))
TypeError: 'str' object is not callable

Code trials:

class Descaro:
    def __init__(self, driver):
        self.driver = driver

    def Descaro(self):
        time.sleep(3)
        self.driver.find_element_by_xpath("//*[@id='splashModal']/a[1]").click()
        print("deberia estar en la pagina de fondo")
        element = WebDriverWait(self.driver, 10)
        element.until(EC.presence_of_element_located(By.XPATH("//*[@id='menu-item-9145']/a'")))
        element.click()

I already try this:

element.until(EC.presence_of_element_located(By.XPATH, '//*[@id="menu-item-9145"]/a''))) 

but doesn't work too , beacuse:

__init__() takes 2 positional arguments but 3 were given

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to take care of a couple of things:


Solution

You need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='menu-item-9145']/a"))).click()

Note: You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Reference

You can find a couple of relevant detailed discussions in:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...