当尝试将文本发送到通过 PrimeFaces 创建的 TextBox 时:
我尝试:
getDriver().findElement(By.id("addRowTable:0:hostName")).sendKeys("testing");
html是:
输入主机名:$(function() {PrimeFaces.cw('Watermark','widget_addRowTable_0_j_idt474',{id:'addRowTable:0:j_idt474',value:'Hostname',target:'addRowTable:0:hostName'},'水印');}); PrimeFaces.cw('InputText','widget_addRowTable_0_hostName',{id:'addRowTable:0:hostName'});.xxxxcxxxxxdddddddddd.net
我得到的 XPath 为:
//*[@id="addRowTable:0:hostName"]
我得到例外:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"addRowTable\\:0\\:hostName"}
Command duration or timeout: 149 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
当我看
http://seleniumhq.org/exceptions/no_such_element.html
我得到一个通用的解释:
The element may not be present.
甚至转义:使用 \ 不起作用
getDriver().findElement(By.id("addRowTable\\:0\\:hostName")).sendKeys("testing");