__init __()接受2个位置参数,但使用Selenium Python使用WebDriverWait和Expected_conditions作为element_to_be_clickable给出了3个
发布于 2021-01-29 15:01:41
我看到了类似的问题,但就我而言,我的代码中甚至没有“
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()
关注者
0
被浏览
72
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")))