Selenium TypeError: __init__() 需要 2 个位置参数,但给出了 3 个 [英] Selenium TypeError: __init__() takes 2 positional arguments but 3 were given

查看:48
本文介绍了Selenium TypeError: __init__() 需要 2 个位置参数,但给出了 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 还是其他任何东西,错误都会重复.

The error repeats itself whether I use By.XPATH, By.ID or anything else.

此外,find_element 工作正常:

Also, find_element works just fine:

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']" 周围的额外括号 () 解决了问题.

Extra parentheses () around By.XPATH, "//input[@id='message']" as suggested in the comments solved the problem.

推荐答案

改变这个

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

我添加了额外的 () ,希望它可以工作.

I have added extra () , hope this should work.

这篇关于Selenium TypeError: __init__() 需要 2 个位置参数,但给出了 3 个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆