python - Selenium 类型错误 : __init__() takes 2 positional arguments but 3 were given

标签 python selenium webdriver

<分区>

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']")))

我添加了额外的 () ,希望它能起作用。

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

相关文章:

python - 导入 Geopandas 时导入错误

python - 从 pyqt4 中的 QTableView 复制/粘贴多个项目?

java - 无法使用 Selenium 单击 href 链接

java - 如何使用 selenium 处理 firefox 中的 "Your connection is not secure"错误

javascript - Selenium 中的 execute_script() 有什么作用

python - 基于索引合并数据帧

python - 从 Keras 预训练网络检索图像的三重模型

java - Selenium java查找多个显示元素

python - 为什么 instagram 不能与 Selenium headless Chrome 一起使用?

java - 如何在 PageFactory @FindBy 注释中使用属性文件值?