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













0















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?










share|improve this question


























    0















    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?










    share|improve this question
























      0












      0








      0








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 7:57









      cristinacristina

      517




      517






















          2 Answers
          2






          active

          oldest

          votes


















          0














          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.






          share|improve this answer




















          • 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


















          0














          You can use the direct xpath to access the label.



          element(by.xpath("//*[@id='Number1']//label"));





          share|improve this answer






















            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%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









            0














            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.






            share|improve this answer




















            • 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















            0














            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.






            share|improve this answer




















            • 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













            0












            0








            0







            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.






            share|improve this answer















            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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












            • 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













            0














            You can use the direct xpath to access the label.



            element(by.xpath("//*[@id='Number1']//label"));





            share|improve this answer



























              0














              You can use the direct xpath to access the label.



              element(by.xpath("//*[@id='Number1']//label"));





              share|improve this answer

























                0












                0








                0







                You can use the direct xpath to access the label.



                element(by.xpath("//*[@id='Number1']//label"));





                share|improve this answer













                You can use the direct xpath to access the label.



                element(by.xpath("//*[@id='Number1']//label"));






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 8:18









                supputurisupputuri

                69049




                69049



























                    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.




                    draft saved


                    draft discarded














                    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





















































                    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

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme