How do I use the XPath substring function in the Chrome inspector?










1














How do I use the XPath substring function in the Chrome inspector? I can't create a working example in the inspector's Elements tab.



For example, this selector:



//div[contains(text(),'Man')]


works on this page, but



substring(//div[contains(text(),'Man')], 2)


fails to select anything. Shouldn't it continue to select the same element as the first selector?



Ultimately I'm passing the second selector to the JavaScript document.evaluate() function in order to get a piece of the text() string. As of now document.evaluate() is not returning anything for the second selector.



PS. I read this question and this one but they don't mention using the Chrome inspector.










share|improve this question





















  • I've tried document.evaluate("substring(//div[contains(text(),'Man')], 2)", document). Works fine, returns XPathResult resultType: 2, stringValue: "Managing Partner, Fort Worth Office↵↵", invalidIteratorState: false
    – Mike Kaskun
    Nov 12 '18 at 8:20










  • What about in the Chrome inspector?
    – prevail
    Nov 12 '18 at 8:48










  • Yea, in inspector(Ctrl+F) does not work :(
    – Mike Kaskun
    Nov 12 '18 at 9:16















1














How do I use the XPath substring function in the Chrome inspector? I can't create a working example in the inspector's Elements tab.



For example, this selector:



//div[contains(text(),'Man')]


works on this page, but



substring(//div[contains(text(),'Man')], 2)


fails to select anything. Shouldn't it continue to select the same element as the first selector?



Ultimately I'm passing the second selector to the JavaScript document.evaluate() function in order to get a piece of the text() string. As of now document.evaluate() is not returning anything for the second selector.



PS. I read this question and this one but they don't mention using the Chrome inspector.










share|improve this question





















  • I've tried document.evaluate("substring(//div[contains(text(),'Man')], 2)", document). Works fine, returns XPathResult resultType: 2, stringValue: "Managing Partner, Fort Worth Office↵↵", invalidIteratorState: false
    – Mike Kaskun
    Nov 12 '18 at 8:20










  • What about in the Chrome inspector?
    – prevail
    Nov 12 '18 at 8:48










  • Yea, in inspector(Ctrl+F) does not work :(
    – Mike Kaskun
    Nov 12 '18 at 9:16













1












1








1







How do I use the XPath substring function in the Chrome inspector? I can't create a working example in the inspector's Elements tab.



For example, this selector:



//div[contains(text(),'Man')]


works on this page, but



substring(//div[contains(text(),'Man')], 2)


fails to select anything. Shouldn't it continue to select the same element as the first selector?



Ultimately I'm passing the second selector to the JavaScript document.evaluate() function in order to get a piece of the text() string. As of now document.evaluate() is not returning anything for the second selector.



PS. I read this question and this one but they don't mention using the Chrome inspector.










share|improve this question













How do I use the XPath substring function in the Chrome inspector? I can't create a working example in the inspector's Elements tab.



For example, this selector:



//div[contains(text(),'Man')]


works on this page, but



substring(//div[contains(text(),'Man')], 2)


fails to select anything. Shouldn't it continue to select the same element as the first selector?



Ultimately I'm passing the second selector to the JavaScript document.evaluate() function in order to get a piece of the text() string. As of now document.evaluate() is not returning anything for the second selector.



PS. I read this question and this one but they don't mention using the Chrome inspector.







javascript google-chrome xpath






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 '18 at 7:31









prevail

182




182











  • I've tried document.evaluate("substring(//div[contains(text(),'Man')], 2)", document). Works fine, returns XPathResult resultType: 2, stringValue: "Managing Partner, Fort Worth Office↵↵", invalidIteratorState: false
    – Mike Kaskun
    Nov 12 '18 at 8:20










  • What about in the Chrome inspector?
    – prevail
    Nov 12 '18 at 8:48










  • Yea, in inspector(Ctrl+F) does not work :(
    – Mike Kaskun
    Nov 12 '18 at 9:16
















  • I've tried document.evaluate("substring(//div[contains(text(),'Man')], 2)", document). Works fine, returns XPathResult resultType: 2, stringValue: "Managing Partner, Fort Worth Office↵↵", invalidIteratorState: false
    – Mike Kaskun
    Nov 12 '18 at 8:20










  • What about in the Chrome inspector?
    – prevail
    Nov 12 '18 at 8:48










  • Yea, in inspector(Ctrl+F) does not work :(
    – Mike Kaskun
    Nov 12 '18 at 9:16















I've tried document.evaluate("substring(//div[contains(text(),'Man')], 2)", document). Works fine, returns XPathResult resultType: 2, stringValue: "Managing Partner, Fort Worth Office↵↵", invalidIteratorState: false
– Mike Kaskun
Nov 12 '18 at 8:20




I've tried document.evaluate("substring(//div[contains(text(),'Man')], 2)", document). Works fine, returns XPathResult resultType: 2, stringValue: "Managing Partner, Fort Worth Office↵↵", invalidIteratorState: false
– Mike Kaskun
Nov 12 '18 at 8:20












What about in the Chrome inspector?
– prevail
Nov 12 '18 at 8:48




What about in the Chrome inspector?
– prevail
Nov 12 '18 at 8:48












Yea, in inspector(Ctrl+F) does not work :(
– Mike Kaskun
Nov 12 '18 at 9:16




Yea, in inspector(Ctrl+F) does not work :(
– Mike Kaskun
Nov 12 '18 at 9:16












1 Answer
1






active

oldest

votes


















0














Seems that in Chrome inspector (using search within DOM - Elements tab) you can't highlight the text only or part of it.



For example, if you try //div[contains(text(),'Man')]/text(), you'll get the whole div element highlighted.



enter image description here



This may explain why substring(//div[contains(text(),'Man')], 2) doesn't work. Sadly, I can't find info about this in documentation.



So, as the alternative you can use $x(path) or Document.evaluate() in Console.

For example,
$x("substring(//div[contains(text(),'Man')], 2)")

or
document.evaluate("substring(//div[contains(text(),'Man')], 2)", document)






share|improve this answer




















  • Thanks but neither one these returns the partial string, so they are not a solution. The result should be naging Partner, Fort Worth Office. The first two chars, Ma, should have been removed by substring().
    – prevail
    Nov 13 '18 at 6:32










  • That's because text inside div is "↵Managing Partner, Fort Worth Office↵↵". So, substring from position 2 returns "Managing Partner, Fort Worth Office↵↵"".
    – Mike Kaskun
    Nov 13 '18 at 7:15











  • You can eliminate leading and trailing white-spaces by normalize-space. So to get "naging Partner, Fort Worth Office" - you'll use substring(normalize-space(//div[contains(text(),'Man')]), 3)
    – Mike Kaskun
    Nov 13 '18 at 7:22










  • Thanks. It works so you have answered my question. I just wish I could get this to work in Node.js. The doc.evaluate() function does not return a match.
    – prevail
    Nov 13 '18 at 23:20










  • I don't know what do you use in nodejs, but you can use evaluate function in jsdom or just use package specifically for xpath.
    – Mike Kaskun
    Nov 14 '18 at 6:22










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236917%2fhow-do-i-use-the-xpath-substring-function-in-the-chrome-inspector%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Seems that in Chrome inspector (using search within DOM - Elements tab) you can't highlight the text only or part of it.



For example, if you try //div[contains(text(),'Man')]/text(), you'll get the whole div element highlighted.



enter image description here



This may explain why substring(//div[contains(text(),'Man')], 2) doesn't work. Sadly, I can't find info about this in documentation.



So, as the alternative you can use $x(path) or Document.evaluate() in Console.

For example,
$x("substring(//div[contains(text(),'Man')], 2)")

or
document.evaluate("substring(//div[contains(text(),'Man')], 2)", document)






share|improve this answer




















  • Thanks but neither one these returns the partial string, so they are not a solution. The result should be naging Partner, Fort Worth Office. The first two chars, Ma, should have been removed by substring().
    – prevail
    Nov 13 '18 at 6:32










  • That's because text inside div is "↵Managing Partner, Fort Worth Office↵↵". So, substring from position 2 returns "Managing Partner, Fort Worth Office↵↵"".
    – Mike Kaskun
    Nov 13 '18 at 7:15











  • You can eliminate leading and trailing white-spaces by normalize-space. So to get "naging Partner, Fort Worth Office" - you'll use substring(normalize-space(//div[contains(text(),'Man')]), 3)
    – Mike Kaskun
    Nov 13 '18 at 7:22










  • Thanks. It works so you have answered my question. I just wish I could get this to work in Node.js. The doc.evaluate() function does not return a match.
    – prevail
    Nov 13 '18 at 23:20










  • I don't know what do you use in nodejs, but you can use evaluate function in jsdom or just use package specifically for xpath.
    – Mike Kaskun
    Nov 14 '18 at 6:22















0














Seems that in Chrome inspector (using search within DOM - Elements tab) you can't highlight the text only or part of it.



For example, if you try //div[contains(text(),'Man')]/text(), you'll get the whole div element highlighted.



enter image description here



This may explain why substring(//div[contains(text(),'Man')], 2) doesn't work. Sadly, I can't find info about this in documentation.



So, as the alternative you can use $x(path) or Document.evaluate() in Console.

For example,
$x("substring(//div[contains(text(),'Man')], 2)")

or
document.evaluate("substring(//div[contains(text(),'Man')], 2)", document)






share|improve this answer




















  • Thanks but neither one these returns the partial string, so they are not a solution. The result should be naging Partner, Fort Worth Office. The first two chars, Ma, should have been removed by substring().
    – prevail
    Nov 13 '18 at 6:32










  • That's because text inside div is "↵Managing Partner, Fort Worth Office↵↵". So, substring from position 2 returns "Managing Partner, Fort Worth Office↵↵"".
    – Mike Kaskun
    Nov 13 '18 at 7:15











  • You can eliminate leading and trailing white-spaces by normalize-space. So to get "naging Partner, Fort Worth Office" - you'll use substring(normalize-space(//div[contains(text(),'Man')]), 3)
    – Mike Kaskun
    Nov 13 '18 at 7:22










  • Thanks. It works so you have answered my question. I just wish I could get this to work in Node.js. The doc.evaluate() function does not return a match.
    – prevail
    Nov 13 '18 at 23:20










  • I don't know what do you use in nodejs, but you can use evaluate function in jsdom or just use package specifically for xpath.
    – Mike Kaskun
    Nov 14 '18 at 6:22













0












0








0






Seems that in Chrome inspector (using search within DOM - Elements tab) you can't highlight the text only or part of it.



For example, if you try //div[contains(text(),'Man')]/text(), you'll get the whole div element highlighted.



enter image description here



This may explain why substring(//div[contains(text(),'Man')], 2) doesn't work. Sadly, I can't find info about this in documentation.



So, as the alternative you can use $x(path) or Document.evaluate() in Console.

For example,
$x("substring(//div[contains(text(),'Man')], 2)")

or
document.evaluate("substring(//div[contains(text(),'Man')], 2)", document)






share|improve this answer












Seems that in Chrome inspector (using search within DOM - Elements tab) you can't highlight the text only or part of it.



For example, if you try //div[contains(text(),'Man')]/text(), you'll get the whole div element highlighted.



enter image description here



This may explain why substring(//div[contains(text(),'Man')], 2) doesn't work. Sadly, I can't find info about this in documentation.



So, as the alternative you can use $x(path) or Document.evaluate() in Console.

For example,
$x("substring(//div[contains(text(),'Man')], 2)")

or
document.evaluate("substring(//div[contains(text(),'Man')], 2)", document)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 10:02









Mike Kaskun

595417




595417











  • Thanks but neither one these returns the partial string, so they are not a solution. The result should be naging Partner, Fort Worth Office. The first two chars, Ma, should have been removed by substring().
    – prevail
    Nov 13 '18 at 6:32










  • That's because text inside div is "↵Managing Partner, Fort Worth Office↵↵". So, substring from position 2 returns "Managing Partner, Fort Worth Office↵↵"".
    – Mike Kaskun
    Nov 13 '18 at 7:15











  • You can eliminate leading and trailing white-spaces by normalize-space. So to get "naging Partner, Fort Worth Office" - you'll use substring(normalize-space(//div[contains(text(),'Man')]), 3)
    – Mike Kaskun
    Nov 13 '18 at 7:22










  • Thanks. It works so you have answered my question. I just wish I could get this to work in Node.js. The doc.evaluate() function does not return a match.
    – prevail
    Nov 13 '18 at 23:20










  • I don't know what do you use in nodejs, but you can use evaluate function in jsdom or just use package specifically for xpath.
    – Mike Kaskun
    Nov 14 '18 at 6:22
















  • Thanks but neither one these returns the partial string, so they are not a solution. The result should be naging Partner, Fort Worth Office. The first two chars, Ma, should have been removed by substring().
    – prevail
    Nov 13 '18 at 6:32










  • That's because text inside div is "↵Managing Partner, Fort Worth Office↵↵". So, substring from position 2 returns "Managing Partner, Fort Worth Office↵↵"".
    – Mike Kaskun
    Nov 13 '18 at 7:15











  • You can eliminate leading and trailing white-spaces by normalize-space. So to get "naging Partner, Fort Worth Office" - you'll use substring(normalize-space(//div[contains(text(),'Man')]), 3)
    – Mike Kaskun
    Nov 13 '18 at 7:22










  • Thanks. It works so you have answered my question. I just wish I could get this to work in Node.js. The doc.evaluate() function does not return a match.
    – prevail
    Nov 13 '18 at 23:20










  • I don't know what do you use in nodejs, but you can use evaluate function in jsdom or just use package specifically for xpath.
    – Mike Kaskun
    Nov 14 '18 at 6:22















Thanks but neither one these returns the partial string, so they are not a solution. The result should be naging Partner, Fort Worth Office. The first two chars, Ma, should have been removed by substring().
– prevail
Nov 13 '18 at 6:32




Thanks but neither one these returns the partial string, so they are not a solution. The result should be naging Partner, Fort Worth Office. The first two chars, Ma, should have been removed by substring().
– prevail
Nov 13 '18 at 6:32












That's because text inside div is "↵Managing Partner, Fort Worth Office↵↵". So, substring from position 2 returns "Managing Partner, Fort Worth Office↵↵"".
– Mike Kaskun
Nov 13 '18 at 7:15





That's because text inside div is "↵Managing Partner, Fort Worth Office↵↵". So, substring from position 2 returns "Managing Partner, Fort Worth Office↵↵"".
– Mike Kaskun
Nov 13 '18 at 7:15













You can eliminate leading and trailing white-spaces by normalize-space. So to get "naging Partner, Fort Worth Office" - you'll use substring(normalize-space(//div[contains(text(),'Man')]), 3)
– Mike Kaskun
Nov 13 '18 at 7:22




You can eliminate leading and trailing white-spaces by normalize-space. So to get "naging Partner, Fort Worth Office" - you'll use substring(normalize-space(//div[contains(text(),'Man')]), 3)
– Mike Kaskun
Nov 13 '18 at 7:22












Thanks. It works so you have answered my question. I just wish I could get this to work in Node.js. The doc.evaluate() function does not return a match.
– prevail
Nov 13 '18 at 23:20




Thanks. It works so you have answered my question. I just wish I could get this to work in Node.js. The doc.evaluate() function does not return a match.
– prevail
Nov 13 '18 at 23:20












I don't know what do you use in nodejs, but you can use evaluate function in jsdom or just use package specifically for xpath.
– Mike Kaskun
Nov 14 '18 at 6:22




I don't know what do you use in nodejs, but you can use evaluate function in jsdom or just use package specifically for xpath.
– Mike Kaskun
Nov 14 '18 at 6:22

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236917%2fhow-do-i-use-the-xpath-substring-function-in-the-chrome-inspector%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)