invalid selector: The result of the xpath expression. It should be an elementjQuery selector regular expressionscontent from divs into textareaHow can I get selenium/cucumber to interact with a “hidden” link that is now in a lightbox/colorbox?What do test automation frameworks provide that my approach of scripting with Selenium Webdriver doesn't?How to find selector for a random ID, XPATH & CSSpath, I'm testing a CMS tool with Selenium c#DOM traversing using jQueryhow to merge duplicated items in javascript array?selenium javascript webdriver - unable to locate dynamic elementXPath returns wrong elementHow to get parent element text and remove child element text selenium c#?

What exactly is a marshrutka (маршрутка)?

Linear Programming with additional "if-then"/"Default to zero" constraints?

Why isn't `typename` required for a base class that is a nested type?

Have there been any countries that voted themselves out of existence?

Why does Coq include let-expressions in its core language

Is this WWI movie scene realistic?

When was the earliest opportunity the Voyager crew had to return to the Alpha quadrant?

Has SHA256 been broken by Treadwell Stanton DuPont?

Is there a real-world mythological counterpart to WoW's "kill your gods for power" theme?

Evidence that matrix multiplication cannot be done in O(n^2 poly(log(n))) time

How do I determine what is "magic" and "bearing magic" for Detect Magic?

What was the relationship between Einstein and Minkowski?

Uncovering the Accelerated Dragon opening

Writing a love interest for my hero

How can I locate a missing person abroad?

Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?

Mean π: Archimedes vs. Gauss - π computation through generalized means

Gas pipes - why does gas burn "outwards?"

Is it appropriate for a professor to require students to sign a non-disclosure agreement before being taught?

Do Milankovitch Cycles fully explain climate change?

Is there any way to land a rover on the Moon without using any thrusters?

Does a gnoll speak both Gnoll and Abyssal, or is Gnoll a dialect of Abyssal?

How can I fix a framing mistake so I can drywall?

A shy person in a queue



invalid selector: The result of the xpath expression. It should be an element


jQuery selector regular expressionscontent from divs into textareaHow can I get selenium/cucumber to interact with a “hidden” link that is now in a lightbox/colorbox?What do test automation frameworks provide that my approach of scripting with Selenium Webdriver doesn't?How to find selector for a random ID, XPATH & CSSpath, I'm testing a CMS tool with Selenium c#DOM traversing using jQueryhow to merge duplicated items in javascript array?selenium javascript webdriver - unable to locate dynamic elementXPath returns wrong elementHow to get parent element text and remove child element text selenium c#?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am writing automation test in selenium with javascript steps. In the test I want to check if TEXT3 equals TEXT3



HTML code of the website:



<div _ngcontent-c35="" class="content">
<p>
TEXT1
<u>
<strong>TEXT2</strong>
</u>
TEXT3
</p>
</div>


Javascript code:



this.Then(/^also "([^"]*)" as loanPurposeInfoDialogLabel03 is displayed$/, function (fieldValue, next) 
var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text()[2]"));
fieldText.getText().then(getFieldValue =>
assert.equal(getFieldValue, fieldValue, next, 'Expected value of loanPurposeInfoDialogLabel03 (Text) to be: ' + fieldValue);
, next);
);


Javascript code does not work in case I use /text() in XPATH



//div[@class='content']/p/text()[2]


I get error:



InvalidSelectorError: invalid selector: The result of the xpath expression "//div[@class='content']/p/text()[2]" is: [object Text]. It should be an element.









share|improve this question






























    1















    I am writing automation test in selenium with javascript steps. In the test I want to check if TEXT3 equals TEXT3



    HTML code of the website:



    <div _ngcontent-c35="" class="content">
    <p>
    TEXT1
    <u>
    <strong>TEXT2</strong>
    </u>
    TEXT3
    </p>
    </div>


    Javascript code:



    this.Then(/^also "([^"]*)" as loanPurposeInfoDialogLabel03 is displayed$/, function (fieldValue, next) 
    var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text()[2]"));
    fieldText.getText().then(getFieldValue =>
    assert.equal(getFieldValue, fieldValue, next, 'Expected value of loanPurposeInfoDialogLabel03 (Text) to be: ' + fieldValue);
    , next);
    );


    Javascript code does not work in case I use /text() in XPATH



    //div[@class='content']/p/text()[2]


    I get error:



    InvalidSelectorError: invalid selector: The result of the xpath expression "//div[@class='content']/p/text()[2]" is: [object Text]. It should be an element.









    share|improve this question


























      1












      1








      1


      1






      I am writing automation test in selenium with javascript steps. In the test I want to check if TEXT3 equals TEXT3



      HTML code of the website:



      <div _ngcontent-c35="" class="content">
      <p>
      TEXT1
      <u>
      <strong>TEXT2</strong>
      </u>
      TEXT3
      </p>
      </div>


      Javascript code:



      this.Then(/^also "([^"]*)" as loanPurposeInfoDialogLabel03 is displayed$/, function (fieldValue, next) 
      var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text()[2]"));
      fieldText.getText().then(getFieldValue =>
      assert.equal(getFieldValue, fieldValue, next, 'Expected value of loanPurposeInfoDialogLabel03 (Text) to be: ' + fieldValue);
      , next);
      );


      Javascript code does not work in case I use /text() in XPATH



      //div[@class='content']/p/text()[2]


      I get error:



      InvalidSelectorError: invalid selector: The result of the xpath expression "//div[@class='content']/p/text()[2]" is: [object Text]. It should be an element.









      share|improve this question














      I am writing automation test in selenium with javascript steps. In the test I want to check if TEXT3 equals TEXT3



      HTML code of the website:



      <div _ngcontent-c35="" class="content">
      <p>
      TEXT1
      <u>
      <strong>TEXT2</strong>
      </u>
      TEXT3
      </p>
      </div>


      Javascript code:



      this.Then(/^also "([^"]*)" as loanPurposeInfoDialogLabel03 is displayed$/, function (fieldValue, next) 
      var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text()[2]"));
      fieldText.getText().then(getFieldValue =>
      assert.equal(getFieldValue, fieldValue, next, 'Expected value of loanPurposeInfoDialogLabel03 (Text) to be: ' + fieldValue);
      , next);
      );


      Javascript code does not work in case I use /text() in XPATH



      //div[@class='content']/p/text()[2]


      I get error:



      InvalidSelectorError: invalid selector: The result of the xpath expression "//div[@class='content']/p/text()[2]" is: [object Text]. It should be an element.






      javascript cucumber gherkin






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 9:11









      Ondrej StrakaOndrej Straka

      62 bronze badges




      62 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          0
















          Because you are giving text() function inside of xpath, please try following code :



          var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text[2]"));





          share|improve this answer

























          • Sorry, but it did not work. code NoSuchElementError: no such element: Unable to locate element: "method":"xpath","selector":"//div[@class='content']/p/text[1]" (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) And if I type xpath above into console of google chrome it does not found text xpath whitout ()

            – Ondrej Straka
            Mar 28 at 17:31












          • What happens when you just use "//div[@class='content']/p" this. it can get all text inside.

            – Selçuk Ayhan
            Mar 29 at 6:35











          • If I use "//div[@class='content']/p" value is TEXT1 TEXT2 TEXT3 so it is not necesery to create step for TEXT3 Thanks :)

            – Ondrej Straka
            Apr 2 at 6:36












          • So that means there is no 3 elements, there is only one element with styling.

            – Selçuk Ayhan
            Apr 2 at 7:04


















          0
















          If I use xpath



          "//div[@class='content']/p"


          value is TEXT1 TEXT2 TEXT3, so it is not necesery to create step for TEXT3



          Thanks to Selçuk Ayhan :)






          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/4.0/"u003ecc by-sa 4.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%2f55393812%2finvalid-selector-the-result-of-the-xpath-expression-it-should-be-an-element%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
















            Because you are giving text() function inside of xpath, please try following code :



            var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text[2]"));





            share|improve this answer

























            • Sorry, but it did not work. code NoSuchElementError: no such element: Unable to locate element: "method":"xpath","selector":"//div[@class='content']/p/text[1]" (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) And if I type xpath above into console of google chrome it does not found text xpath whitout ()

              – Ondrej Straka
              Mar 28 at 17:31












            • What happens when you just use "//div[@class='content']/p" this. it can get all text inside.

              – Selçuk Ayhan
              Mar 29 at 6:35











            • If I use "//div[@class='content']/p" value is TEXT1 TEXT2 TEXT3 so it is not necesery to create step for TEXT3 Thanks :)

              – Ondrej Straka
              Apr 2 at 6:36












            • So that means there is no 3 elements, there is only one element with styling.

              – Selçuk Ayhan
              Apr 2 at 7:04















            0
















            Because you are giving text() function inside of xpath, please try following code :



            var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text[2]"));





            share|improve this answer

























            • Sorry, but it did not work. code NoSuchElementError: no such element: Unable to locate element: "method":"xpath","selector":"//div[@class='content']/p/text[1]" (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) And if I type xpath above into console of google chrome it does not found text xpath whitout ()

              – Ondrej Straka
              Mar 28 at 17:31












            • What happens when you just use "//div[@class='content']/p" this. it can get all text inside.

              – Selçuk Ayhan
              Mar 29 at 6:35











            • If I use "//div[@class='content']/p" value is TEXT1 TEXT2 TEXT3 so it is not necesery to create step for TEXT3 Thanks :)

              – Ondrej Straka
              Apr 2 at 6:36












            • So that means there is no 3 elements, there is only one element with styling.

              – Selçuk Ayhan
              Apr 2 at 7:04













            0














            0










            0









            Because you are giving text() function inside of xpath, please try following code :



            var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text[2]"));





            share|improve this answer













            Because you are giving text() function inside of xpath, please try following code :



            var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text[2]"));






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 15:46









            Selçuk AyhanSelçuk Ayhan

            8878 silver badges17 bronze badges




            8878 silver badges17 bronze badges















            • Sorry, but it did not work. code NoSuchElementError: no such element: Unable to locate element: "method":"xpath","selector":"//div[@class='content']/p/text[1]" (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) And if I type xpath above into console of google chrome it does not found text xpath whitout ()

              – Ondrej Straka
              Mar 28 at 17:31












            • What happens when you just use "//div[@class='content']/p" this. it can get all text inside.

              – Selçuk Ayhan
              Mar 29 at 6:35











            • If I use "//div[@class='content']/p" value is TEXT1 TEXT2 TEXT3 so it is not necesery to create step for TEXT3 Thanks :)

              – Ondrej Straka
              Apr 2 at 6:36












            • So that means there is no 3 elements, there is only one element with styling.

              – Selçuk Ayhan
              Apr 2 at 7:04

















            • Sorry, but it did not work. code NoSuchElementError: no such element: Unable to locate element: "method":"xpath","selector":"//div[@class='content']/p/text[1]" (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) And if I type xpath above into console of google chrome it does not found text xpath whitout ()

              – Ondrej Straka
              Mar 28 at 17:31












            • What happens when you just use "//div[@class='content']/p" this. it can get all text inside.

              – Selçuk Ayhan
              Mar 29 at 6:35











            • If I use "//div[@class='content']/p" value is TEXT1 TEXT2 TEXT3 so it is not necesery to create step for TEXT3 Thanks :)

              – Ondrej Straka
              Apr 2 at 6:36












            • So that means there is no 3 elements, there is only one element with styling.

              – Selçuk Ayhan
              Apr 2 at 7:04
















            Sorry, but it did not work. code NoSuchElementError: no such element: Unable to locate element: "method":"xpath","selector":"//div[@class='content']/p/text[1]" (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) And if I type xpath above into console of google chrome it does not found text xpath whitout ()

            – Ondrej Straka
            Mar 28 at 17:31






            Sorry, but it did not work. code NoSuchElementError: no such element: Unable to locate element: "method":"xpath","selector":"//div[@class='content']/p/text[1]" (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information) And if I type xpath above into console of google chrome it does not found text xpath whitout ()

            – Ondrej Straka
            Mar 28 at 17:31














            What happens when you just use "//div[@class='content']/p" this. it can get all text inside.

            – Selçuk Ayhan
            Mar 29 at 6:35





            What happens when you just use "//div[@class='content']/p" this. it can get all text inside.

            – Selçuk Ayhan
            Mar 29 at 6:35













            If I use "//div[@class='content']/p" value is TEXT1 TEXT2 TEXT3 so it is not necesery to create step for TEXT3 Thanks :)

            – Ondrej Straka
            Apr 2 at 6:36






            If I use "//div[@class='content']/p" value is TEXT1 TEXT2 TEXT3 so it is not necesery to create step for TEXT3 Thanks :)

            – Ondrej Straka
            Apr 2 at 6:36














            So that means there is no 3 elements, there is only one element with styling.

            – Selçuk Ayhan
            Apr 2 at 7:04





            So that means there is no 3 elements, there is only one element with styling.

            – Selçuk Ayhan
            Apr 2 at 7:04













            0
















            If I use xpath



            "//div[@class='content']/p"


            value is TEXT1 TEXT2 TEXT3, so it is not necesery to create step for TEXT3



            Thanks to Selçuk Ayhan :)






            share|improve this answer





























              0
















              If I use xpath



              "//div[@class='content']/p"


              value is TEXT1 TEXT2 TEXT3, so it is not necesery to create step for TEXT3



              Thanks to Selçuk Ayhan :)






              share|improve this answer



























                0














                0










                0









                If I use xpath



                "//div[@class='content']/p"


                value is TEXT1 TEXT2 TEXT3, so it is not necesery to create step for TEXT3



                Thanks to Selçuk Ayhan :)






                share|improve this answer













                If I use xpath



                "//div[@class='content']/p"


                value is TEXT1 TEXT2 TEXT3, so it is not necesery to create step for TEXT3



                Thanks to Selçuk Ayhan :)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 2 at 6:46









                Ondrej StrakaOndrej Straka

                62 bronze badges




                62 bronze badges































                    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%2f55393812%2finvalid-selector-the-result-of-the-xpath-expression-it-should-be-an-element%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript