I need an Xpath expression that will select values that start with a certain value. For this instance I am using the id field.
@id=[starts-with(name(),'value')
The following does not work. Is there a way to use the starts-with command with the value between the tags? Or is there another means in xpath of selecting a matching a value with a known value.
Here is a sample of the xml I am trying to drill into:
<bean> <id>AnnotationsBasedJMXAutoExporter</id> <class>org.springframework.jmx.export.MBeanExporter</class> <lazy-init>false</lazy-init> <property>assembler <!-- will create management interface using annotation metadata --> <bean>
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')]"));
So, inorder to find the Text all you need to do is: driver. findElement(By. xpath("//*[contains(text(),'the text you are searching for')]"));
The XPath default axis is child , so your predicate [*/android.widget.TextView[@androidXtext='Microwaves']] is equivalent to [child::*/child::android.widget.TextView[@androidXtext='Microwaves']] This predicate will select nodes with a android. widget. TextView grandchild and the specified attribute.
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.
I think this xpath should work //id[starts-with(text(),'Annotations')]
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