简体   繁体   中英

Xpath that find a specific text and only this specific text

I'm using an xpath to locate element that contains a certain text in it. My problem is that it locate another element that have the same text i'm looking for in it but also some other text, here the xpath i'm using is:

//a[contains(text(), 'Workflow')]

And i want to locate a link that contain the text Workflow and Workflow only, but the xpath locate a link with Workflow.MAINMENU wich i don't want to.

Is this possible with an XPATH ?

Yes, this is possible. You need to not use the contains function, but to instead compare the text directly:

//a[text() = 'Workflow']

If there is whitespace surrounding the text, you could use:

//a[normalize-space(text()) = 'Workflow']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM