expected_conditions._find_element抛出错误:AttributeError:' str'对象没有属性' find_element'

时间:2017-10-13 04:59:57

标签: python selenium

我必须等待一些元素出现,我使用:

re_enter_email_field = WebDriverWait(self.driver, 10).until(
                expected_conditions._find_element(By.ID,"u_0_f"))

但每次我进行测试时,都会收到错误:

Error

  File "/home/akop/py_workspace/MacPaw_FB/pages/LoginPage.py", line 56, in submit_new_account_form
    expected_conditions._find_element(By.ID,"u_0_f"))
  File "/home/akop/py_workspace/t_sade_site/site_env/lib/python3.5/site-packages/selenium/webdriver/support/expected_conditions.py", line 398, in _find_element
    return driver.find_element(*by)
AttributeError: 'str' object has no attribute 'find_element'

3 个答案:

答案 0 :(得分:0)

我知道你使用的是Python,但是在Java上我这样做:

new WebDriverWait(driver, EXPLICIT_TIMEOUT)
            .until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver driver) {
                    return driver.findElements(By.id("my_id")).isEmpty();
                }
            });

答案 1 :(得分:0)

答案更容易:(By.ID,"u_0_f")周围的额外括号解决了问题

答案 2 :(得分:0)

我不知道这段代码是什么意思,因为我对python知之甚少但是我猜错了:

expected_conditions._find_element(By.ID,"u_0_f")

但expected_conditions应该遵循条件,如element_to_be_clickable,presence_of_element_located或visibility_of_element_located等。

你应该尝试这样

re_enter_email_field = WebDriverWait(driver, 10).until(
        expected_conditions.visibility_of_element_located(By.ID,"u_0_f"))

re_enter_email_field = WebDriverWait(driver, 10).until(
        expected_conditions.presence_of_element_located(By.ID,"u_0_f"))

re_enter_email_field = WebDriverWait(driver, 10).until(
        expected_conditions.element_to_be_clickable(By.ID,"u_0_f"))