<table>
<tr>
<td>hi</td>
</tr>
</table>
<button id="change" onclick="change()">change</button>
<script>
function change(){
$("table").empty();
var $tr = $("<tr></tr>");
$tr.append( $("<td>bye</td>") );
}
</script>
WebDriver driver=new ChromeDriver(chromeOptions);
WebElement change= driver.findElement(By.id("change"));
change.click();
WebElement td=driver.findElement(By.xpath("//*table/tr/td[1]"));
System.out.println(td.getText());
我期待“再見”,但它列印了“嗨”。
如何獲得動態更改的文本?
uj5u.com熱心網友回復:
通過使用WebDriverWait顯式等待,您可以獲得初始元素文本內容。然后等待該文本在單擊后不再出現在該元素中,然后獲取新的元素文本內容。如下:
WebDriverWait wait = new WebDriverWait(webDriver, 20);
WebElement td =driver.findElement(By.xpath("//*table/tr/td[1]"));
String oldText = td.getText();
driver.findElement(By.id("change")).click();
wait.until(ExpectedConditions.not(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*table/tr/td[1]"), oldText)));
System.out.println(td.getText());
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/507724.html
標籤:爪哇 硒 硒网络驱动程序 硒铬驱动程序 网络驱动程序等待
上一篇:從谷歌地圖獲取緯度和經度
下一篇:如何在此特定按鈕上執行單擊操作?
