Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find elements using text without tag

HTML

<div class="cell">
<!---->
message.
<!----></div>

Trying to write an XPath using text then click on the element.

My locator

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(//td[@class="el-table_1_column_5 el-table__cell"]//div[contains(text(),'')])[1]

but when I enter text in the above element, it is not found.

(//td[@class="el-table_1_column_5 el-table__cell"]//div[contains(text(),'message')])[1]

>Solution :

The problem is that the "message" text is likely not the first text node inside of the DIV. That’s why

(//td[@class="el-table_1_column_5 el-table__cell"]//div[contains(text(),'message')])[1]

is not working. Change text() to . and I expect it will work.

(//td[@class="el-table_1_column_5 el-table__cell"]//div[contains(.,'message')])[1]

Read this on the difference between . and text() in XPath.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading