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

                    Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                    Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                    How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page