Using XPath- starts-with method, we can write the Java code along with the dynamic XPath location as: findElement(By. xpath("//*[starts-with(@id,'lst')]"));
The '*' is used for selecting all the element nodes descending from the current node with @id-attribute-value equal to 'Passwd'.
XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.
What Is Dynamic XPath In Selenium? XPath, also known as XML Path, is one of Selenium WebDriver's most commonly used locators for navigating through a page's HTML structure. It can be used to locate any element in a web page using HTML DOM structure in HTML and XML documents.
Use:
/*/ITEM[starts-with(REVENUE_YEAR,'2552')]/REGION
Note: Unless your host language can't handle element instance as result, do not use text nodes specially in mixed content data model. Do not start expressions with //
operator when the schema is well known.
Use:
//REVENUE_YEAR[starts-with(.,'2552')]/../REGION/text()
Try this
//ITEM/*[starts-with(text(),'2552')]/following-sibling::*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With