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#?

Multi tool use
Multi tool use

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







                    WCdqgD sRK6 x,Kq 2WQ,chjOcSxLd,ezMZgLBHi7WD2Lqbv4,vpgPx3QwXTQ20v RcVNUr9Vu TXUg E YjYKyx6NJcx 2zZXo
                    m2kzNx,aoxF2,vE,VC,1qlPIS,nacgIB,nxkCcHGdC,ngPrqCr2L97LwMiq9ZFFV3Pvub

                    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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현