python/selenium:如何将any_of与element_to_be_clickable一起使用

问题描述 投票:0回答:1

我的

selenium
-项目需要等待三个元素中的某个元素变得可点击。

我正在使用此代码 atm:

LOC1 = (By.ID, "ID1")
LOC2 = (By.ID, "ID2")
LOC2 = (By.ID, "ID3")
def get_correct_el(self):
    def wait_for_el():
        return self.robot.wait.until(
            EC.any_of(
                EC.element_to_be_clickable(LOC1),
                EC.element_to_be_clickable(LOC2),
                EC.element_to_be_clickable(LOC3),
            )
        )
    el = wait_for_el()
    while el != self.driver.find_element(*LOC1):
        el.click()
        el = wait_for_el()

代码可以工作,但 linter 抱怨:

Argument of type "(WebDriverOrWebElement) -> (WebElement | Literal[False])" cannot be assigned to parameter "expected_conditions" of type "(D@any_of) -> T@any_of" in function "any_of"
  Type "(WebDriverOrWebElement) -> (WebElement | Literal[False])" cannot be assigned to type "(Unknown) -> WebElement"
    Function return type "WebElement | Literal[False]" is incompatible with type "WebElement"
      Type "WebElement | Literal[False]" cannot be assigned to type "WebElement"
        "Literal[False]" is incompatible with "WebElement"PylancereportArgumentType
(function) def element_to_be_clickable(mark: WebElement | Tuple[str, str]) -> ((WebDriverOrWebElement) -> (WebElement | Literal[False]))
An Expectation for checking an element is visible and enabled such that you can click it.

element is either a locator (text) or an WebElement

这是一个我可以安全忽略的错误,还是我错误地使用了这些函数?

谢谢!

编辑:这是

any_of
抱怨类型,而不是
element_to_be_clickable

any_of
期望:
*expected_conditions: Callable[[D], T]

element_to_be_clickable
返回:
Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]

我明白,签名不匹配,我的问题是我应该如何将

any_of
element_to_be_clickable
一起使用。

python selenium-webdriver
1个回答
0
投票

这是一个警告。 您在

element_to_be_clickable
中传递的参数与所需类型不对应。像这样的事情可能会导致意外的行为(很难预测)。

参数可能是一个返回

WebElement
实例或
False
的函数,但编译器期望一个返回
WebElement
实例的函数。

我没有从您的代码中看到您传递的参数。但如果我是你,我会修复它。

© www.soinside.com 2019 - 2024. All rights reserved.