This question already has an answer here:
Selenium - visibility_of_element_located: __init__() takes exactly 2 arguments (3 given)

(1个答案)


3年前关闭。



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
driver = webdriver.Firefox()
driver.get("http://somelink.com/")


WebDriverWait(driver, 10).until(expected_conditions.invisibility_of_element_located(By.XPATH, "//input[@id='message']"))
# Gives me an error:
TypeError: __init__() takes 2 positional arguments but 3 were given

...
# Simply:
expected_conditions.invisibility_of_element_located(By.XPATH, "//input[@id='message']"))
# Gives me the same error.
TypeError: __init__() takes 2 positional arguments but 3 were given

无论我使用By.XPATH,By.ID还是其他任何方式,该错误都会重复发生。

另外,find_element可以正常工作:
el = driver.find_element(By.XPATH, "//input[@id='message']")
print(el) # returns:
[<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="03cfc338-f668-4fcd-b312-8e4a1cfd9f24", element="c7f76445-08b3-4a4c-9d04-90263a1ef80e")>]

建议表示赞赏。

编辑:

如注释中所建议,在By.XPATH, "//input[@id='message']"周围加上了括号()解决了该问题。

最佳答案

改变这个

WebDriverWait(driver, 10).until(expected_conditions.invisibility_of_element_locate‌​d((By.XPATH, "//input[@id='message']")))

我添加了extra(),希望它能工作。

关于python - Selenium TypeError : __init__() takes 2 positional arguments but 3 were given,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39684653/

10-11 07:24