Xpath using matches and Regex working in Xpath tester but in code throwing InvalidSelectorException Failed to...











up vote
1
down vote

favorite












HTML



<div class="top-section" style="" xpath="1">
<input id="role" value="admin" hidden="">
<small>Welcome </small> <b style="">8828024404, MCGM</b>
<a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
<a href="/logout" class="float-right logout">Log Out</a>
</input>
</div>


String to search



8828024404, MCGM


Xpath Expression



//b[matches(text(),'[0-9]{10}, [A-Za-z]*')]


Exception




org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
to locate an element with the xpath expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
string '//b[matches(text(),'[0-9]{10}, [A-Za-z]
')]' is not a valid
XPath expression. (Session info: chrome=70.0.3538.102) (Driver
info: chromedriver=2.42.591088
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds











share|improve this question




























    up vote
    1
    down vote

    favorite












    HTML



    <div class="top-section" style="" xpath="1">
    <input id="role" value="admin" hidden="">
    <small>Welcome </small> <b style="">8828024404, MCGM</b>
    <a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
    <a href="/logout" class="float-right logout">Log Out</a>
    </input>
    </div>


    String to search



    8828024404, MCGM


    Xpath Expression



    //b[matches(text(),'[0-9]{10}, [A-Za-z]*')]


    Exception




    org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
    to locate an element with the xpath expression
    //b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
    error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
    string '//b[matches(text(),'[0-9]{10}, [A-Za-z]
    ')]' is not a valid
    XPath expression. (Session info: chrome=70.0.3538.102) (Driver
    info: chromedriver=2.42.591088
    (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
    10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds











    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      HTML



      <div class="top-section" style="" xpath="1">
      <input id="role" value="admin" hidden="">
      <small>Welcome </small> <b style="">8828024404, MCGM</b>
      <a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
      <a href="/logout" class="float-right logout">Log Out</a>
      </input>
      </div>


      String to search



      8828024404, MCGM


      Xpath Expression



      //b[matches(text(),'[0-9]{10}, [A-Za-z]*')]


      Exception




      org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
      to locate an element with the xpath expression
      //b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
      error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
      string '//b[matches(text(),'[0-9]{10}, [A-Za-z]
      ')]' is not a valid
      XPath expression. (Session info: chrome=70.0.3538.102) (Driver
      info: chromedriver=2.42.591088
      (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
      10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds











      share|improve this question















      HTML



      <div class="top-section" style="" xpath="1">
      <input id="role" value="admin" hidden="">
      <small>Welcome </small> <b style="">8828024404, MCGM</b>
      <a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
      <a href="/logout" class="float-right logout">Log Out</a>
      </input>
      </div>


      String to search



      8828024404, MCGM


      Xpath Expression



      //b[matches(text(),'[0-9]{10}, [A-Za-z]*')]


      Exception




      org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
      to locate an element with the xpath expression
      //b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
      error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
      string '//b[matches(text(),'[0-9]{10}, [A-Za-z]
      ')]' is not a valid
      XPath expression. (Session info: chrome=70.0.3538.102) (Driver
      info: chromedriver=2.42.591088
      (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
      10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds








      selenium selenium-webdriver xpath






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 at 20:42









      DebanjanB

      35.4k73271




      35.4k73271










      asked Nov 17 at 19:34









      Jeevan Nikam

      203




      203
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Selenium supports XPath 1.0 version while fn:matches is from XPath 2.0.



          If you want to match bold text that starts with 10 digits before comma, you can try below XPath



          //b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]


          Let me know in case you have more constraints to required element






          share|improve this answer




























            up vote
            0
            down vote













            Quite not sure about your exact usecase why you want a xpath to search for a Regex.



            However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.



            In this case you can use either of the following solutions:





            • XPath 1:



              //div[@class='top-section']/input[@id='role' and @value='admin']//b



            • XPath 2:



              //div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]







            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',
              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%2f53354813%2fxpath-using-matches-and-regex-working-in-xpath-tester-but-in-code-throwing-inval%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



              accepted










              Selenium supports XPath 1.0 version while fn:matches is from XPath 2.0.



              If you want to match bold text that starts with 10 digits before comma, you can try below XPath



              //b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]


              Let me know in case you have more constraints to required element






              share|improve this answer

























                up vote
                1
                down vote



                accepted










                Selenium supports XPath 1.0 version while fn:matches is from XPath 2.0.



                If you want to match bold text that starts with 10 digits before comma, you can try below XPath



                //b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]


                Let me know in case you have more constraints to required element






                share|improve this answer























                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  Selenium supports XPath 1.0 version while fn:matches is from XPath 2.0.



                  If you want to match bold text that starts with 10 digits before comma, you can try below XPath



                  //b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]


                  Let me know in case you have more constraints to required element






                  share|improve this answer












                  Selenium supports XPath 1.0 version while fn:matches is from XPath 2.0.



                  If you want to match bold text that starts with 10 digits before comma, you can try below XPath



                  //b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]


                  Let me know in case you have more constraints to required element







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 17 at 19:57









                  Andersson

                  34.8k103066




                  34.8k103066
























                      up vote
                      0
                      down vote













                      Quite not sure about your exact usecase why you want a xpath to search for a Regex.



                      However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.



                      In this case you can use either of the following solutions:





                      • XPath 1:



                        //div[@class='top-section']/input[@id='role' and @value='admin']//b



                      • XPath 2:



                        //div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]







                      share|improve this answer



























                        up vote
                        0
                        down vote













                        Quite not sure about your exact usecase why you want a xpath to search for a Regex.



                        However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.



                        In this case you can use either of the following solutions:





                        • XPath 1:



                          //div[@class='top-section']/input[@id='role' and @value='admin']//b



                        • XPath 2:



                          //div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]







                        share|improve this answer

























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Quite not sure about your exact usecase why you want a xpath to search for a Regex.



                          However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.



                          In this case you can use either of the following solutions:





                          • XPath 1:



                            //div[@class='top-section']/input[@id='role' and @value='admin']//b



                          • XPath 2:



                            //div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]







                          share|improve this answer














                          Quite not sure about your exact usecase why you want a xpath to search for a Regex.



                          However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.



                          In this case you can use either of the following solutions:





                          • XPath 1:



                            //div[@class='top-section']/input[@id='role' and @value='admin']//b



                          • XPath 2:



                            //div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]








                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 18 at 16:39

























                          answered Nov 17 at 20:44









                          DebanjanB

                          35.4k73271




                          35.4k73271






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354813%2fxpath-using-matches-and-regex-working-in-xpath-tester-but-in-code-throwing-inval%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

                              Costa Masnaga

                              Fotorealismo

                              Sidney Franklin