微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – Selenium TypeError:__ init __()需要2个位置参数但是3个被赋予

参见英文答案 > Selenium – visibility_of_element_located: __init__() takes exactly 2 arguments (3 given)                                    1个

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周围的额外括号(),评论中建议的“//输入[@ id =’message’]”解决了问题.

解决方法

改变这个

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

添加了额外的(),希望这应该工作.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐