我在 selenium 工作,現在為了檢查元素的可見性,我使用以下等待:@FindBy (css=".delete-basket-modal-btn") WebElement deleteItemFromBasketCancelButton;public void clickDeleteItemFromBasketCancelButton() throws InterruptedException { wait.until(ExpectedConditions.elementToBeClickable(deleteItemFromBasketCancelButton)); deleteItemFromBasketCancelButton.click();}這不是個好主意,此功能不檢查元素的存在,所以有時我會得到“過時的元素參考元素未附加到頁面文檔”現在我試圖創建通用函數,它將被我的所有頁面對象類繼承。在此函數中,我需要檢查(5 秒)傳入參數的 WebElement 的存在、啟用、可點擊性和可見性。目前我在下面有新功能,但我不知道這是解決我問題的好方法public void verifyElement(WebElement element) throws InterruptedException { boolean isPresent = false; for (int i = 0; i < 5; i++) { try { if (element != null) { isPresent = true; // metoda do czekania na element break; } } catch (Exception e) { // System.out.println(e.getLocalizedMessage()); Thread.sleep(1000); } } Assert.assertTrue(isPresent, "\"" + element + "\" is not present."); boolean isEnabled = false; for (int i = 0; i < 5; i++) { try { if (element.isEnabled()==true) { isEnabled = true; break; } }catch (Exception e) { Thread.sleep(1000); }} Assert.assertTrue(isEnabled, "\"" + element + "\" is not enabled.");}您對這個問題有什么建議或類似的問題嗎?
添加回答
舉報
0/150
提交
取消