![](/img/trans.png)
[英]How to concatenate two webelement, iterate it and get the text out of concatenated Xpath
[英]Get the text out of an WebElement found by id update by jquery
我正在嘗試從ID和ID中獲取一些文本,以便稍后在測試中使用它。 我可以找到與元素:
WebElement jrnrText = driver.findElement(
By.id("ctl00_content_createnewschema_modalAlert_alertMessage"))
但是問題是該值稍后將由jquery動態添加,因此,當我到達頁面時,該ID將存在。 然后,我單擊一個按鈕,jQuery將更新ID。
我知道我可以使用jrnrText.getText(),但這不會給我任何東西,因為在單擊按鈕之前id不包含任何東西。
這是我的代碼:
driver.findElement(By.id("ctl00_content_createnewschema_btnCreate")).click();
WebElement jrnrText = driver.findElement(
By.id("ctl00_content_createnewschema_modalAlert_alertMessage"))
if(jrnrText.isDisplayed()){
wait.until(presenceOfElementLocated(By.xpath('''//td[contains(text(),"part of the text"]''')))
}
println jrnrText.getText()
您的問題令人困惑,但我會盡力回答。 首先,如果元素的ID根據用戶輸入而動態變化,那么它將完全違背ID的目的。 這是應該在網站中修復的錯誤。
如果由於某種原因無法修復該錯誤,那么我們將需要更多詳細信息。 您在上面顯示的代碼中的哪里失敗? 當您說“該ID在我單擊按鈕之前不包含任何內容”時,是否表示該ID為“ ctl00_content_createnewschema_modalAlert_alertMessage”的元素不存在? 即使發生在您所說的單擊按鈕之后更新了ID?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.