__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


- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01