简体   繁体   中英

Unable to locate xpath element text that contains carriage return

I am unable to find the text value of the below a tag with the below Xpath. The text that is for the tag contains carriage returns, I assumed that contains would ignore this. Is there a way to search the text attribute and ignore carriage returns?

//*[@id='site-wrapper']//a[contains(text(), 'Report')]

<a target="_blank" href="/Bentley/Reports/74/0/5323914">
            <span class="fa fa-print"></span> Report
        </a>

That's because contains() function expects a string argument, thus text() node-set will be converted taking the first node in document order and then by string() function.

When you have mixed content, it's always better to use the string value instead of text nodes, like:

//*[@id='site-wrapper']//a[contains(., 'Report')]

尝试使用 normalize-space:

//*[@id='site-wrapper']//a[normalize-space(text())='Report']

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