__init__() takes 2 positional arguments but 3 were given using WebDriverWait and expected_conditions as element_to_be_clickable with Selenium Python(__init__() 接受 2 个位置参数,但使用 WebDriverWait 和 expected_conditions 给出了 3 个作为 element_to_be_clickable 和 Selenium
问题描述
我看到了类似的问题,但就我而言,我的代码中甚至没有init"函数.如何解决这个问题呢?问题在于 (EC.element_to_bo_clickable)
I saw similar questions but in my case there is not even "init" function in my code. How to solve this problem? The problem is with line (EC.element_to_bo_clickable)
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path="C:Chromedriverchromedriver.exe")
driver.implicitly_wait(1)
driver.get("https://cct-103.firebaseapp.com/")
element = WebDriverWait(driver, 1).until
(EC.element_to_be_clickable(By.CLASS_NAME, "MuiButton-label"))
element.click()
推荐答案
根据定义,element_to_be_clickable()
应该在 tuple
中调用,因为它不是 函数 而是一个 class,其中初始化器只期望 implicit self 之外的 1 参数:
According to the definition, element_to_be_clickable()
should be called within a tuple
as it is not a function but a class, where the initializer expects just 1 argument beyond the implicit self:
class element_to_be_clickable(object):
""" An Expectation for checking an element is visible and enabled such that you can click it."""
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
element = visibility_of_element_located(self.locator)(driver)
if element and element.is_enabled():
return element
else:
return False
所以而不是:
element = WebDriverWait(driver, 1).until(EC.element_to_be_clickable(By.CLASS_NAME, "MuiButton-label"))
您需要(添加额外的括号):
You need to (add an extra parentheses):
element = WebDriverWait(driver, 1).until((EC.element_to_be_clickable(By.CLASS_NAME, "MuiButton-label")))
这篇关于__init__() 接受 2 个位置参数,但使用 WebDriverWait 和 expected_conditions 给出了 3 个作为 element_to_be_clickable 和 Selenium Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:__init__() 接受 2 个位置参数,但使用 WebDriverWait 和 expected_conditions 给出了 3 个作为 element_to_be_clickable 和 Selenium Python


基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01