How to get the node with certain text value in xpath?

Viewed 43

I have a very long website with many script nodes, how can I access to the one that has 'var config' in the text with xpath?

<script>
    var config = {
        locale: 'es',
        userAuthenticated: false
}
<script>
1 Answers

In case this is the only node with script tag name having config attribute you can use the following XPath to locate it:

"//script[@config]"

In case there is some unique value inside the config values, like userAuthenticated here XPath like this could be used:

"//script[contains(@config,'userAuthenticated')]"

UPD
The element you are looking for can be located with the following XPath:

"//script[contains(.,'userAuthenticated')]"
Related