第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Selenium WebDriver如何解決過時(shí)的元素參考異常?

Selenium WebDriver如何解決過時(shí)的元素參考異常?

慕桂英3389331 2019-08-02 16:31:00
Selenium WebDriver如何解決過時(shí)的元素參考異常?我在Selenium 2 Web驅(qū)動(dòng)程序測(cè)試中有以下代碼,它在我調(diào)試時(shí)有效,但是當(dāng)我在構(gòu)建中運(yùn)行它時(shí)大部分時(shí)間都失敗了。我知道它必須與頁(yè)面沒有刷新的方式有關(guān),但不知道如何解決它所以任何關(guān)于我做錯(cuò)了什么的指針都表示贊賞。我使用JSF primefaces作為我的Web應(yīng)用程序框架。當(dāng)我點(diǎn)擊添加新鏈接時(shí),會(huì)出現(xiàn)一個(gè)彈出對(duì)話框,其中包含一個(gè)我可以輸入日期的輸入框,然后單擊保存。它是在輸入元素輸入文本,我得到一個(gè)陳舊的元素引用異常。提前致謝import static org.junit.Assert.assertEquals; import java.util.HashMap;import java.util.List;import java.util.Map;import org.junit.Test;import org.openqa.selenium.By;import org.openqa.selenium.StaleElementReferenceException;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.support.ui.ExpectedCondition;import org.openqa.selenium.support.ui.WebDriverWait;public class EnterActiveSubmissionIntegrationTest {Map<String, Map<String, String>> tableData = new HashMap<String, Map<String, String>>();@Testpublic void testEnterActiveSubmission() throws Exception {    // Create a new instance of the Firefox driver    // Notice that the remainder of the code relies on the interface,     // not the implementation.    System.setProperty("webdriver.chrome.driver", "C:/apps/chromedriver.exe");    WebDriver driver = new ChromeDriver();    // And now use this to visit Google    driver.get("http://localhost:8080/strfingerprinting");    // Alternatively the same thing can be done like this    // driver.navigate().to("http://www.google.com");    // Find the text input element by its name    WebElement element = driver.findElement(By.linkText("Manage Submissions"));    element.click();    parseTableData(driver, "form:submissionDataTable_data", 1);    assertEquals(tableData.get("form:submissionDataTable_data").get("12"), "Archived");    WebElement newElement = driver.findElement(By.linkText("Add new"));    newElement.click();
查看完整描述

3 回答

?
烙印99

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊

首先讓我們清楚一下WebElement是什么。

WebElement是對(duì)DOM中元素的引用。

當(dāng)您正在交互的元素被銷毀然后重新創(chuàng)建時(shí),拋出StaleElementException。如今,大多數(shù)復(fù)雜的網(wǎng)頁(yè)都會(huì)隨著用戶與之交互而動(dòng)態(tài)移動(dòng),這需要銷毀和重新創(chuàng)建DOM中的元素。

當(dāng)發(fā)生這種情況時(shí),您之前使用的DOM中元素的引用變得陳舊,您不再能夠使用此引用與DOM中的元素進(jìn)行交互。當(dāng)發(fā)生這種情況時(shí),您需要刷新您的參考,或者在現(xiàn)實(shí)世界中,再次找到該元素。


查看完整回答
反對(duì) 回復(fù) 2019-08-02
?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊

這不是問題。如果將.findElement調(diào)用包裝在try-catch塊中并捕獲StaleElementReferenceException,則可以根據(jù)需要循環(huán)并重試多次,直到成功為止。

以下是我寫的一些例子。

Selenide項(xiàng)目的另一個(gè)例子:

public static final Condition hidden = new Condition("hidden", true) {
    @Override
    public boolean apply(WebElement element) {
      try {
        return !element.isDisplayed();
      } catch (StaleElementReferenceException elementHasDisappeared) {
        return true;
      }
    }
  };


查看完整回答
反對(duì) 回復(fù) 2019-08-02
  • 3 回答
  • 0 關(guān)注
  • 1012 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)