2017-10-13 94 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")) 
相關問題