__init__() 需要 2 个位置参数,但 3 个是使用 WebDriverWait 和 expected_conditions 作为 element_to_be_clickable 和 Selenium Python 给出的 [英] __init__() takes 2 positional arguments but 3 were given using WebDriverWait and expected_conditions as element_to_be_clickable with Selenium Python
本文介绍了__init__() 需要 2 个位置参数,但 3 个是使用 WebDriverWait 和 expected_conditions 作为 element_to_be_clickable 和 Selenium Python 给出的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到了类似的问题,但就我而言,我的代码中甚至没有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:\Chromedriver\chromedriver.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
中调用,因为它不是一个函数 而是一个类,其中初始化器只需要隐式 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 个位置参数,但 3 个是使用 WebDriverWait 和 expected_conditions 作为 element_to_be_clickable 和 Selenium Python 给出的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文