Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath expression to find values that start with

Tags:

xpath

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> 
like image 904
Will Avatar asked May 17 '13 10:05

Will


People also ask

How do you write starting with XPath?

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')]"));

How do I search for text in XPath?

So, inorder to find the Text all you need to do is: driver. findElement(By. xpath("//*[contains(text(),'the text you are searching for')]"));

What does * indicate in XPath?

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.

What is text () in XPath?

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.


1 Answers

I think this xpath should work //id[starts-with(text(),'Annotations')]

like image 155
Ievgen Avatar answered Sep 27 '22 19:09

Ievgen