Exmple feed: view-source:http://rss.packetstormsecurity.org/files/tags/exploit/
I only want to return sections of xml where the parent title node has matching text in it, in this example the text to match is "site".
//get feed with curl
$doc = new SimpleXmlElement($xml, LIBXML_NOCDATA);
//$result = $doc->xpath('//title'); //this works returns all the <title>'s
$result = $doc->xpath('//title[site]'); //doesn't work
$result = $doc->xpath('//title[text()="site"]'); //doesn't work
$result = $doc->xpath('//title[contains(site)]'); //doesn't work
$result = $doc->xpath('//title[contains(text(),'Site')]'); //doesn't work
foreach ($result as $title)
echo "$title<br />"
So, inorder to find the Text all you need to do is: driver. findElement(By. xpath("//*[contains(text(),'the text you are searching for')]"));
5) XPath Text() Function The XPath text() function is a built-in function of selenium webdriver which is used to locate elements based on text of a web element. It helps to find the exact text elements and it locates the elements within the set of text nodes. The elements to be located should be in string form.
Syntax of XPath //: Used to select the current node. tagname: Name of the tag of a particular node. @: Used to select the select attribute. Attribute: Name of the attribute of the node.
We will start to write XPath with //, followed by input tag, then we will use the select attribute, followed by its attribute name like name, id, etc, and then we will choose a value of attribute in single quotes. Here, (1 of 1) means exact match. It indicates that there is only one element available for this XPath.
The call you need is, I think, this:
$result = $xpath->query('//title[contains(.,"Site")]');
Note that this is case-sensitive.
Note that the contains
XPath function takes two arguments: a haystack and a needle. In this case, we are using the current node's text value as the haystack, which is indicated by the use of the dot (.
).
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