2017-08-07 56 views
0

我已經使用Selenium進行了大量測試。我想盡可能強化我的測試。我想知道我應該使用ElementToBeClickable還是使用elementExisits或兩者。顯式等待最準確結果的最佳實踐

比如我應該使用

方法1

public static WebDriverWait webDriverWait; 
webDriverWait = new WebDriverWait(excelSession, TimeSpan.FromSeconds(60)); 

webDriverWait.Until(ExpectedConditions.ElementTo‌​BeClickable(wordSession.FindElementByName("Create"))).Click(); 

方法2

By create = By.Name("Create"); 
       webDriverWait.Until(ExpectedConditions.ElementExists(create)).Click(); 

方法3

 By create = By.Name("Create"); 
     webDriverWait.Until(ExpectedConditions.ElementExists(create)).Click(); 
     webDriverWait.Until(ExpectedConditions.ElementTo‌​BeClickable(excelSession.FindElement(create))).Click(); 
+0

如果元素應該在通道的下方點擊,我們應該只使用ElementToBeClickable。 'ExpectedConditions'必須根據你獨特的動作來設置。謝謝 – DebanjanB

+0

我總是比較喜歡在我的大多數情況下使用ElementIsClickable。如果由於某種原因ElementIsClickable不起作用(對於禁用的項目),最好將其與其他一些檢查結合起來,並檢查其他一些兄弟元素的可用性。 –

+3

我正在投票結束此問題爲基於意見。我們不能知道你應該做什麼,我們只能根據它的文檔來說明你的API是應該做什麼的,這也是你閱讀的內容來回答你的問題。當然,可能有多種方法來解決你的問題,但是選擇哪一種取決於你。 – HimBromBeere

回答

1

如果該元素將在稍後被點擊你可以使用fol降低代碼

webDriverWait.Until(ExpectedConditions.ElementTo‌BeClickable(wordSession.FindElementByName("Create"))).Click(); 
webDriverWait.Until(ExpectedConditions.ElementExists(create)).Click(); 

這種情況在少數情況下不起作用。它檢查元素在DOM中是否可用。它不檢查元素是否在UI中可見。

您應該使用ElementIsVisible而不是,它工作正常。