Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :(

like image 343
Ranjana Avatar asked Jul 05 '26 08:07

Ranjana


1 Answers

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']"));
like image 150
nilesh Avatar answered Jul 07 '26 05:07

nilesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!