How to get Text from a div element returns just a “.” with Selenium











up vote
0
down vote

favorite












I have a div element which looks like below.



enter image description here



I identify this element with the following xpath.



//*[contains(@class,'ce-component-title')]


Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.



enter image description here



Any help would be much appreciated.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have a div element which looks like below.



    enter image description here



    I identify this element with the following xpath.



    //*[contains(@class,'ce-component-title')]


    Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.



    enter image description here



    Any help would be much appreciated.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a div element which looks like below.



      enter image description here



      I identify this element with the following xpath.



      //*[contains(@class,'ce-component-title')]


      Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.



      enter image description here



      Any help would be much appreciated.










      share|improve this question















      I have a div element which looks like below.



      enter image description here



      I identify this element with the following xpath.



      //*[contains(@class,'ce-component-title')]


      Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.



      enter image description here



      Any help would be much appreciated.







      java selenium xpath css-selectors webdriverwait






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 5:01









      DebanjanB

      37.7k73375




      37.7k73375










      asked Nov 20 at 4:36









      mayooran

      1,65932856




      1,65932856
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:





          • cssSelector:



            String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");



          • xpath:



            String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");







          share|improve this answer























          • Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
            – mayooran
            Nov 20 at 8:53










          • Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
            – DebanjanB
            Nov 20 at 9:02


















          up vote
          0
          down vote













          I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
          Try using console of your browser, to verify how many elements this xpath returns.
          I can help you if you give me url to this page.






          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%2f53386312%2fhow-to-get-text-from-a-div-element-returns-just-a-with-selenium%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








            up vote
            1
            down vote













            As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:





            • cssSelector:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");



            • xpath:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");







            share|improve this answer























            • Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
              – mayooran
              Nov 20 at 8:53










            • Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
              – DebanjanB
              Nov 20 at 9:02















            up vote
            1
            down vote













            As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:





            • cssSelector:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");



            • xpath:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");







            share|improve this answer























            • Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
              – mayooran
              Nov 20 at 8:53










            • Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
              – DebanjanB
              Nov 20 at 9:02













            up vote
            1
            down vote










            up vote
            1
            down vote









            As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:





            • cssSelector:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");



            • xpath:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");







            share|improve this answer














            As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:





            • cssSelector:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");



            • xpath:



              String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 20 at 9:01

























            answered Nov 20 at 4:56









            DebanjanB

            37.7k73375




            37.7k73375












            • Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
              – mayooran
              Nov 20 at 8:53










            • Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
              – DebanjanB
              Nov 20 at 9:02


















            • Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
              – mayooran
              Nov 20 at 8:53










            • Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
              – DebanjanB
              Nov 20 at 9:02
















            Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
            – mayooran
            Nov 20 at 8:53




            Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
            – mayooran
            Nov 20 at 8:53












            Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
            – DebanjanB
            Nov 20 at 9:02




            Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
            – DebanjanB
            Nov 20 at 9:02












            up vote
            0
            down vote













            I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
            Try using console of your browser, to verify how many elements this xpath returns.
            I can help you if you give me url to this page.






            share|improve this answer



























              up vote
              0
              down vote













              I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
              Try using console of your browser, to verify how many elements this xpath returns.
              I can help you if you give me url to this page.






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
                Try using console of your browser, to verify how many elements this xpath returns.
                I can help you if you give me url to this page.






                share|improve this answer














                I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
                Try using console of your browser, to verify how many elements this xpath returns.
                I can help you if you give me url to this page.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 at 15:31









                meagar

                176k29272288




                176k29272288










                answered Nov 21 at 1:28









                Dmitry

                35427




                35427






























                    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%2f53386312%2fhow-to-get-text-from-a-div-element-returns-just-a-with-selenium%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

                    Create new schema in PostgreSQL using DBeaver

                    Deepest pit of an array with Javascript: test on Codility

                    Costa Masnaga