selenium webdriver -xpath generation selenium webdriver -xpath generation selenium selenium

selenium webdriver -xpath generation


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.