小编典典

__init __()接受2个位置参数,但使用Selenium Python使用WebDriverWait和Expected_conditions作为element_to_be_clickable给出了3个

python

我看到了类似的问题,但就我而言,我的代码中甚至没有“
init”函数。如何解决这个问题呢?问题是线(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()

阅读 274

收藏
2021-01-20

共1个答案

小编典典

根据定义,element_to_be_clickable()应在a中调用tuple它,因为它不是
函数 而是 ,其中初始化程序期望 隐式 self* 之外仅包含 1个 参数: __*

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"))

您需要(添加一个额外的括号):

element = WebDriverWait(driver, 1).until((EC.element_to_be_clickable(By.CLASS_NAME, "MuiButton-label")))
2021-01-20