Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath and innerHTML

What Xpath expression can I use to find all the anchor (just 'a') elements whose actual text (the innerHTML) is Logout.

something like

//a[@innerHTML='Logout']

Would that be correct?

like image 897
Jonathan. Avatar asked May 09 '10 15:05

Jonathan.


People also ask

How do I get inner HTML using XPath?

How do I get inner HTML using XPath? you can use XPath to select just content in one of two ways: Text Node Selection. This XPath, //div[@class='myclass']/text() will select the text node children of the targeted div element, content , as requested.

Can we use XPath in JavaScript?

This document describes the interface for using XPath in JavaScript internally, in extensions, and from websites. Mozilla implements a fair amount of the DOM 3 XPath, which means that XPath expressions can be run against both HTML and XML documents.

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.

What is the difference between DOT and text in XPath?

enter image description here The XPath text() function locates elements within a text node while dot (.) locate elements inside or outside a text node.


1 Answers

No, it would be incorrect. innerHTML is a property, part of the object model, while XPath operates on tags and attributes. Unless your a tag actually has an attribute named innerHTML, this wouldn't work.

If you want to compare the value of the tag itself, you can use the . (dot) to refer to the tag:

a[.='Logout']

However, I must add, just in case you're using jQuery: I'm not sure if it will work with jQuery. jQuery does not support XPath fully, only basic stuff.

like image 120
Fyodor Soikin Avatar answered Oct 12 '22 02:10

Fyodor Soikin