How to get descendants with a specific tag name and text in protractor?can you spot the error in this xpathXPath to find nodes with text + all their descendants & siblings that match certain criteriaSelenium webdriver using TestNG - Cannot locate correct Xpath of input field from labelHow can I return this checkbox element with Protractor?Selenium IDE / Xpath verifying a checkbox is checked only if the element's label contains specific textby.cssContainingText in Python/SeleniumProtractor/XPath - Find element that contains a descendant that contains textProtractor stopped clicking on the buttons throughout the siteClick on a specific item on a list with similar ngcontent classname but has a span unique text using Protractor typescriptXPath select input which occure before some div with different text
node command while defining a coordinate in TikZ
Does "Dominei" mean something?
My boss asked me to take a one-day class, then signs it up as a day off
Meta programming: Declare a new struct on the fly
The most efficient algorithm to find all possible integer pairs which sum to a given integer
Are Warlocks Arcane or Divine?
Was the picture area of a CRT a parallelogram (instead of a true rectangle)?
Can a Bard use an arcane focus?
What was required to accept "troll"?
Did US corporations pay demonstrators in the German demonstrations against article 13?
Adding empty element to declared container without declaring type of element
Indicating multiple different modes of speech (fantasy language or telepathy)
Latex for-and in equation
Teaching indefinite integrals that require special-casing
Visiting the UK as unmarried couple
What is the term when two people sing in harmony, but they aren't singing the same notes?
What is the opposite of 'gravitas'?
Calculating the number of days between 2 dates in Excel
What to do when my ideas aren't chosen, when I strongly disagree with the chosen solution?
Is a naturally all "male" species possible?
Would it be legal for a US State to ban exports of a natural resource?
Can the harmonic series explain the origin of the major scale?
Why are on-board computers allowed to change controls without notifying the pilots?
Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)
How to get descendants with a specific tag name and text in protractor?
can you spot the error in this xpathXPath to find nodes with text + all their descendants & siblings that match certain criteriaSelenium webdriver using TestNG - Cannot locate correct Xpath of input field from labelHow can I return this checkbox element with Protractor?Selenium IDE / Xpath verifying a checkbox is checked only if the element's label contains specific textby.cssContainingText in Python/SeleniumProtractor/XPath - Find element that contains a descendant that contains textProtractor stopped clicking on the buttons throughout the siteClick on a specific item on a list with similar ngcontent classname but has a span unique text using Protractor typescriptXPath select input which occure before some div with different text
I have the following structure (it's just for sample). In protractor, I am getting the top element by id. However, the other elements do not have id's. I need to get the "label" element that contains the text '20'. Is there an easy way in protractor to select the element with a specific tag that contains a specific text from all the descendants of a parent element?
<pc-selector _... id="Number1">
<div ...></div>
<div ...>
<div ...>
<check-box _...>
<div _ngcontent-c25="" ...>
<label _ngcontent-c25="">
<input _ngcontent-c25="" type="checkbox">
<span _ngcontent-c25="" class="m-checkbox__marker"></span>
20 More text to follow</label>
</div>
</check-box>
</div>
</div>
</pc-selector>
I could't find anythitng, so I have tried with xpath, but protractor complains that my xpath is invalid:
parentElement = element(by.id('Number1'));
return parentElement.element(by.xpath(".//label[contains(text(),'20'))]"));
Any ideas?
xpath protractor
add a comment |
I have the following structure (it's just for sample). In protractor, I am getting the top element by id. However, the other elements do not have id's. I need to get the "label" element that contains the text '20'. Is there an easy way in protractor to select the element with a specific tag that contains a specific text from all the descendants of a parent element?
<pc-selector _... id="Number1">
<div ...></div>
<div ...>
<div ...>
<check-box _...>
<div _ngcontent-c25="" ...>
<label _ngcontent-c25="">
<input _ngcontent-c25="" type="checkbox">
<span _ngcontent-c25="" class="m-checkbox__marker"></span>
20 More text to follow</label>
</div>
</check-box>
</div>
</div>
</pc-selector>
I could't find anythitng, so I have tried with xpath, but protractor complains that my xpath is invalid:
parentElement = element(by.id('Number1'));
return parentElement.element(by.xpath(".//label[contains(text(),'20'))]"));
Any ideas?
xpath protractor
add a comment |
I have the following structure (it's just for sample). In protractor, I am getting the top element by id. However, the other elements do not have id's. I need to get the "label" element that contains the text '20'. Is there an easy way in protractor to select the element with a specific tag that contains a specific text from all the descendants of a parent element?
<pc-selector _... id="Number1">
<div ...></div>
<div ...>
<div ...>
<check-box _...>
<div _ngcontent-c25="" ...>
<label _ngcontent-c25="">
<input _ngcontent-c25="" type="checkbox">
<span _ngcontent-c25="" class="m-checkbox__marker"></span>
20 More text to follow</label>
</div>
</check-box>
</div>
</div>
</pc-selector>
I could't find anythitng, so I have tried with xpath, but protractor complains that my xpath is invalid:
parentElement = element(by.id('Number1'));
return parentElement.element(by.xpath(".//label[contains(text(),'20'))]"));
Any ideas?
xpath protractor
I have the following structure (it's just for sample). In protractor, I am getting the top element by id. However, the other elements do not have id's. I need to get the "label" element that contains the text '20'. Is there an easy way in protractor to select the element with a specific tag that contains a specific text from all the descendants of a parent element?
<pc-selector _... id="Number1">
<div ...></div>
<div ...>
<div ...>
<check-box _...>
<div _ngcontent-c25="" ...>
<label _ngcontent-c25="">
<input _ngcontent-c25="" type="checkbox">
<span _ngcontent-c25="" class="m-checkbox__marker"></span>
20 More text to follow</label>
</div>
</check-box>
</div>
</div>
</pc-selector>
I could't find anythitng, so I have tried with xpath, but protractor complains that my xpath is invalid:
parentElement = element(by.id('Number1'));
return parentElement.element(by.xpath(".//label[contains(text(),'20'))]"));
Any ideas?
xpath protractor
xpath protractor
asked Mar 8 at 7:57
cristinacristina
517
517
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You have an additional bracket in your [contains(text(),'20'))] which is likely causing you issue but there are multiple other ways this can be achieved using a single XPath or chaining other locators.
The process is that you must find the div with the correct id first and then locate the label that is a child of it.
//Xpath
element(by.xpath("//pc-selector[@id='Number1']//label[contains(text(),'20')]"));
//Chained CSS
element(by.id('Number1')).element(by.cssContainingText('label','20'));
You also may be interested to learn about xpath axes which can allow us to do very dynamic selection.
1
It works when I run this xpath: "//*[@id=Number1']//label" and I get all the label elements. However, once I try to filter them by text "//*[@id='Number1']//label[contains(text(),'20')]", it cannot find any element. However, the chained css worked, thanks!
– cristina
Mar 8 at 9:39
Yeah as you mentioned//*[@id=Number1']//label
will return all label elements so I didn't feel that satisfied your question. I think I should have used a dot in place of the text() (//pc-selector[@id='Number1']//label[contains(.,'20')
) but not 100% certain. Did you retry your original attempt with the unnecessary bracket removed?
– DublinDev
Mar 8 at 9:53
add a comment |
You can use the direct xpath to access the label.
element(by.xpath("//*[@id='Number1']//label"));
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%2f55058916%2fhow-to-get-descendants-with-a-specific-tag-name-and-text-in-protractor%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have an additional bracket in your [contains(text(),'20'))] which is likely causing you issue but there are multiple other ways this can be achieved using a single XPath or chaining other locators.
The process is that you must find the div with the correct id first and then locate the label that is a child of it.
//Xpath
element(by.xpath("//pc-selector[@id='Number1']//label[contains(text(),'20')]"));
//Chained CSS
element(by.id('Number1')).element(by.cssContainingText('label','20'));
You also may be interested to learn about xpath axes which can allow us to do very dynamic selection.
1
It works when I run this xpath: "//*[@id=Number1']//label" and I get all the label elements. However, once I try to filter them by text "//*[@id='Number1']//label[contains(text(),'20')]", it cannot find any element. However, the chained css worked, thanks!
– cristina
Mar 8 at 9:39
Yeah as you mentioned//*[@id=Number1']//label
will return all label elements so I didn't feel that satisfied your question. I think I should have used a dot in place of the text() (//pc-selector[@id='Number1']//label[contains(.,'20')
) but not 100% certain. Did you retry your original attempt with the unnecessary bracket removed?
– DublinDev
Mar 8 at 9:53
add a comment |
You have an additional bracket in your [contains(text(),'20'))] which is likely causing you issue but there are multiple other ways this can be achieved using a single XPath or chaining other locators.
The process is that you must find the div with the correct id first and then locate the label that is a child of it.
//Xpath
element(by.xpath("//pc-selector[@id='Number1']//label[contains(text(),'20')]"));
//Chained CSS
element(by.id('Number1')).element(by.cssContainingText('label','20'));
You also may be interested to learn about xpath axes which can allow us to do very dynamic selection.
1
It works when I run this xpath: "//*[@id=Number1']//label" and I get all the label elements. However, once I try to filter them by text "//*[@id='Number1']//label[contains(text(),'20')]", it cannot find any element. However, the chained css worked, thanks!
– cristina
Mar 8 at 9:39
Yeah as you mentioned//*[@id=Number1']//label
will return all label elements so I didn't feel that satisfied your question. I think I should have used a dot in place of the text() (//pc-selector[@id='Number1']//label[contains(.,'20')
) but not 100% certain. Did you retry your original attempt with the unnecessary bracket removed?
– DublinDev
Mar 8 at 9:53
add a comment |
You have an additional bracket in your [contains(text(),'20'))] which is likely causing you issue but there are multiple other ways this can be achieved using a single XPath or chaining other locators.
The process is that you must find the div with the correct id first and then locate the label that is a child of it.
//Xpath
element(by.xpath("//pc-selector[@id='Number1']//label[contains(text(),'20')]"));
//Chained CSS
element(by.id('Number1')).element(by.cssContainingText('label','20'));
You also may be interested to learn about xpath axes which can allow us to do very dynamic selection.
You have an additional bracket in your [contains(text(),'20'))] which is likely causing you issue but there are multiple other ways this can be achieved using a single XPath or chaining other locators.
The process is that you must find the div with the correct id first and then locate the label that is a child of it.
//Xpath
element(by.xpath("//pc-selector[@id='Number1']//label[contains(text(),'20')]"));
//Chained CSS
element(by.id('Number1')).element(by.cssContainingText('label','20'));
You also may be interested to learn about xpath axes which can allow us to do very dynamic selection.
edited Mar 8 at 9:05
answered Mar 8 at 8:58
DublinDevDublinDev
9721317
9721317
1
It works when I run this xpath: "//*[@id=Number1']//label" and I get all the label elements. However, once I try to filter them by text "//*[@id='Number1']//label[contains(text(),'20')]", it cannot find any element. However, the chained css worked, thanks!
– cristina
Mar 8 at 9:39
Yeah as you mentioned//*[@id=Number1']//label
will return all label elements so I didn't feel that satisfied your question. I think I should have used a dot in place of the text() (//pc-selector[@id='Number1']//label[contains(.,'20')
) but not 100% certain. Did you retry your original attempt with the unnecessary bracket removed?
– DublinDev
Mar 8 at 9:53
add a comment |
1
It works when I run this xpath: "//*[@id=Number1']//label" and I get all the label elements. However, once I try to filter them by text "//*[@id='Number1']//label[contains(text(),'20')]", it cannot find any element. However, the chained css worked, thanks!
– cristina
Mar 8 at 9:39
Yeah as you mentioned//*[@id=Number1']//label
will return all label elements so I didn't feel that satisfied your question. I think I should have used a dot in place of the text() (//pc-selector[@id='Number1']//label[contains(.,'20')
) but not 100% certain. Did you retry your original attempt with the unnecessary bracket removed?
– DublinDev
Mar 8 at 9:53
1
1
It works when I run this xpath: "//*[@id=Number1']//label" and I get all the label elements. However, once I try to filter them by text "//*[@id='Number1']//label[contains(text(),'20')]", it cannot find any element. However, the chained css worked, thanks!
– cristina
Mar 8 at 9:39
It works when I run this xpath: "//*[@id=Number1']//label" and I get all the label elements. However, once I try to filter them by text "//*[@id='Number1']//label[contains(text(),'20')]", it cannot find any element. However, the chained css worked, thanks!
– cristina
Mar 8 at 9:39
Yeah as you mentioned
//*[@id=Number1']//label
will return all label elements so I didn't feel that satisfied your question. I think I should have used a dot in place of the text() (//pc-selector[@id='Number1']//label[contains(.,'20')
) but not 100% certain. Did you retry your original attempt with the unnecessary bracket removed?– DublinDev
Mar 8 at 9:53
Yeah as you mentioned
//*[@id=Number1']//label
will return all label elements so I didn't feel that satisfied your question. I think I should have used a dot in place of the text() (//pc-selector[@id='Number1']//label[contains(.,'20')
) but not 100% certain. Did you retry your original attempt with the unnecessary bracket removed?– DublinDev
Mar 8 at 9:53
add a comment |
You can use the direct xpath to access the label.
element(by.xpath("//*[@id='Number1']//label"));
add a comment |
You can use the direct xpath to access the label.
element(by.xpath("//*[@id='Number1']//label"));
add a comment |
You can use the direct xpath to access the label.
element(by.xpath("//*[@id='Number1']//label"));
You can use the direct xpath to access the label.
element(by.xpath("//*[@id='Number1']//label"));
answered Mar 8 at 8:18
supputurisupputuri
69049
69049
add a comment |
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.
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%2f55058916%2fhow-to-get-descendants-with-a-specific-tag-name-and-text-in-protractor%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