2017-10-13 93 views
0

我要等待一些元素的外观,我用:expected_conditions._find_element抛出一个错误:AttributeError的:“海峡”对象有没有属性“find_element”

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' 
+0

我认为,如果它解决您的问题,你的元素不存在 – iamsankalp89

回答

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(); 
       } 
      }); 
0

回答是容易得多:约(By.ID,"u_0_f")额外parenthes解决了这个问题

+0

好。 – iamsankalp89

0

我不知道是什么意思是,这代码的,因为我有非常少的蟒蛇的知识,但它是不正确的我猜:

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")) 
相关问题