selenium webdriver -xpath 生成 [英] selenium webdriver -xpath generation

查看:24
本文介绍了selenium webdriver -xpath 生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 selenium webdriver 工作.我有几个文本框的 id 会一直改变.

I am working in selenium webdriver.I have few text boxes whose ids are going to change all the time.

例如 id=ctl00_SPWebPartManager1_g_ad39b78c_a97b_4431_aedb_c9e6270134c6_ctl00_wizNotification_ucChangeData_txtAddress1

但最后一部分始终保持不变.在上面的例子中 wizNotification_ucChangeData_txtAddress1我曾尝试使用 xpath,例如:

but last part remains same always. in above example wizNotification_ucChangeData_txtAddress1 i have tried to go with xpath like:

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

但在运行时无法识别文本区域.

but while running not able to identify the textarea.

请提出任何建议.我也尝试过://input[ends-with(@id,'wizNotification_ucChangeData_txtAddress1')] 但没有运气:(

Any suggestions please. I tried as well with: //input[ends-with(@id,'wizNotification_ucChangeData_txtAddress1')] but no Luck :(

推荐答案

Xpaths 在 IE 中很慢,因为 IE 没有原生 Xpath 引擎.您应该改用 CSS Selector 以获得更好的性能.至于你的情况,你可以尝试下面的 css 选择器,它会找到一个 id 以 txtAddress1

Xpaths are slow in IE because IE does not have native Xpath engine. You should instead use CSS Selector for better performance. As for your case, you can try below css selector which finds an input for which the id ends with txtAddress1

E[foo$="bar"] 一个 E 元素,其foo"属性值恰好以字符串bar"结尾

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

这篇关于selenium webdriver -xpath 生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆