早上好家伙!我在使用 Selenium Webdriver (JAVA) 進行自動化時遇到問題。首先,系統(tǒng)(界面)使用AJAX,好嗎?!我必須多次點擊同一個按鈕。該按鈕保留相同的元素。為了避免錯誤(ElementClickInterceptedException 和/或 StaleElementReferenceException),我最初添加了一個帶有異?!癳lementToBeClickable”的 WebdriverWait。然而,即使這樣等待,錯誤仍然存在。然后我決定添加 FluentWait。我添加了例外、時間等,但也保留了錯誤。我發(fā)現(xiàn)唯一有效的替代方案是著名的“Thread.sleep”(400ms)。但我不想將 thread.sleep 添加到我的代碼中,因為我發(fā)現(xiàn)這是一個不好的做法。有人有什么想法嗎?下面是一些代碼片段。命令:driver.findElement(By.xpath("//tr[1]/td[8]/button"))。點擊 ();等待已使用:1:wait.until (ExpectedConditions.elementToBeClickable (By.xpath ("// tr / td [8] / button")));2:wait.until (ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath ("// tr / td [8] / button")));3: .withTimeout (10, TimeUnit.SECONDS)
.pollingEvery (1, TimeUnit.SECONDS)
.ignoring (NoSuchElementException.class)
.ignoring (StaleElementReferenceException.class)
.ignoring (ElementClickInterceptedException.class);
waitFluent.until (ExpectedConditions.elementToBeClickable (By.xpath ("// tr / td [8] / button")));有誰能夠幫助我?預先非常感謝您!
1 回答

眼眸繁星
TA貢獻1873條經驗 獲得超9個贊
您能否上傳該應用程序的 html 源代碼以及您的問題?還要檢查該按鈕元素是否位于任何 iframe 標記內,如果是,則必須實現(xiàn) driver.switchTo().frame(iFrame)。
添加回答
舉報
0/150
提交
取消