2011-09-14 99 views
3

我在硒webdriver.I有几个文本框的ID将会改变所有的时间。selenium webdriver -xpath生成

e.g id=ctl00_SPWebPartManager1_g_ad39b78c_a97b_4431_aedb_c9e6270134c6_ctl00_wizNotification_ucChangeData_txtAddress1

但最后仍然相同始终。在上面的例子中wizNotification_ucChangeData_txtAddress1 我曾尝试去使用XPath,如:

//input[contains(@id,'txtAddress1') 
//input[ends-with(@id,'txtAddress1')] 

,但在运行不能够识别的文本区域。

请提出任何建议。 我试着以及同://input[ends-with(@id,'wizNotification_ucChangeData_txtAddress1')]但没有运气:(

回答

1

尝试:

.//input[@id[contains(.,'txtAddress1' )]]

要小心,如果是一个textarea它不会被检测为输入

3

Xpaths在IE中很慢,因为IE没有本地的Xpath引擎,你应该改用CSS Selector来获得更好的性能。至于你的情况,你可以试试下面的css选择器,用于查找id以txtAddress1结尾的输入

E [FOO $ = “酒吧”]的E元素 “foo” 的属性值完全与字符串 “bar”

WebElement element = driver.findElement(By.cssSelector("input[id$='txtAddress1']")); 
0

在具有动态IDS webelements的情况下结束,而不是去为Xpath的,有了Ids,我们可以通过其他方式寻找像'by tagname',CSSlocator这样的元素,它为我工作。