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












0















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





























    0















    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



























      0












      0








      0








      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 '18 at 5:01









      DebanjanB

      40k73577




      40k73577










      asked Nov 20 '18 at 4:36









      mayooranmayooran

      1,68432858




      1,68432858
























          2 Answers
          2






          active

          oldest

          votes


















          1














          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 '18 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 '18 at 9:02



















          0














          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









            1














            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 '18 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 '18 at 9:02
















            1














            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 '18 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 '18 at 9:02














            1












            1








            1







            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 '18 at 9:01

























            answered Nov 20 '18 at 4:56









            DebanjanBDebanjanB

            40k73577




            40k73577













            • 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 9:02













            0














            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






























              0














              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




























                0












                0








                0







                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 '18 at 15:31









                meagar

                178k29272288




                178k29272288










                answered Nov 21 '18 at 1:28









                DmitryDmitry

                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.




                    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

                    MongoDB - Not Authorized To Execute Command

                    Npm cannot find a required file even through it is in the searched directory

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith