How do I use the XPath substring function in the Chrome inspector?
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
add a comment |
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
I've trieddocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
. Works fine, returnsXPathResult 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
add a comment |
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
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
javascript google-chrome xpath
asked Nov 10 '18 at 7:31
prevail
182
182
I've trieddocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
. Works fine, returnsXPathResult 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
add a comment |
I've trieddocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
. Works fine, returnsXPathResult 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
add a comment |
1 Answer
1
active
oldest
votes
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.
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)")
ordocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
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 insidediv
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 bynormalize-space
. So to get "naging Partner, Fort Worth Office" - you'll usesubstring(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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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)")
ordocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
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 insidediv
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 bynormalize-space
. So to get "naging Partner, Fort Worth Office" - you'll usesubstring(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
add a comment |
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.
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)")
ordocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
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 insidediv
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 bynormalize-space
. So to get "naging Partner, Fort Worth Office" - you'll usesubstring(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
add a comment |
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.
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)")
ordocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
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.
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)")
ordocument.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
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 insidediv
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 bynormalize-space
. So to get "naging Partner, Fort Worth Office" - you'll usesubstring(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
add a comment |
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 insidediv
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 bynormalize-space
. So to get "naging Partner, Fort Worth Office" - you'll usesubstring(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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I've tried
document.evaluate("substring(//div[contains(text(),'Man')], 2)", document)
. Works fine, returnsXPathResult 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