开发者

selenium webdriver -xpath generation

I am working 开发者_如何学运维in selenium webdriver.I have few text boxes whose ids are going to change all the time.

e.g id=ctl00_SPWebPartManager1_g_ad39b78c_a97b_4431_aedb_c9e6270134c6_ctl00_wizNotification_ucChangeData_txtAddress1

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.

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


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"] an E element whose "foo" attribute value ends exactly with the string "bar"

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


Try:

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

Be careful, if is a textarea it won't be detected as an input.


In case of webelements with dynamic Ids, instead of going for Xpath with Ids we can go for other way of finding elements like 'by tagname', CSSlocator,.. it worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜