How to write an XPath using AND Operator to add multiple spans in a single XPath?












1















The page contains a Product name-(3 OF 3) GOLDEN GLOW ( DELUXE ).
The product name has 6 different spans so we want to print the product name "GOLDEN GLOW ( DELUXE )", i.e including the all the spans so I have tried to use the and multiple time inside the but it didn't work. Below is the XPath:



//*[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') contains(@class, 'no-mobile') ]


Below is the HTML code:



<span class="m-shopping-cart-item-header-number">
(
<span id="itemNo-1" class="itemNo">3</span>
of
<span id="totalItems-1" class="totalItems">3</span>
)
<span class="itemTitleCopy no-mobile" id="itemTitleCopy-1">Golden Glow</span>
<span class="no-mobile">(</span>
<span class="sizeDescriptionTitle no-mobile" id="sizeDescriptionTitle-1">Deluxe</span>
<span class="no-mobile">)</span>
</span>




Update



Code trials:



WebElement checkoutShippingProdName = new WebDriverWait(getDriver(), 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='m-shopping-cart-item-header-number']"))); 
String shipProdElementHtml = checkoutShippingProdName.getAttribute("innerHTML");
String shipProdElementHtmlHtmlSplit = shipProdElementHtml.split("span>");
String currentProd = shipProdElementHtmlHtmlSplit[shipProdElementHtmlHtmlSplit.length -1];
currentProd = StringEscapeUtils.unescapeHtml4(StringUtils.trim(currentProd));
System.out.println("The Product Name is:" + currentProd);









share|improve this question




















  • 1





    Edit your question with HTML sample, your current XPath, current output, desired output

    – Andersson
    Jan 3 at 12:37











  • I think you are missing and operator before last cotains.

    – Amrendra Kumar
    Jan 3 at 12:41











  • Post XML which will help us to find the problem.

    – Amrendra Kumar
    Jan 3 at 12:43











  • I want to prinit the product name i.e Golden Glow ( Deluxe ) ignoring the (3 of 3) so to get this I am trying to use the AND operatier to write the Xptah //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') and contains(@class, 'no-mobile') ]

    – user3538483
    Jan 3 at 12:58











  • And it didn't work i am able to use and operatior only once i.e //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') ] till this I am able to identify the Elment but if I use the all the and operator 3 times I am not able to identify elment.

    – user3538483
    Jan 3 at 12:59
















1















The page contains a Product name-(3 OF 3) GOLDEN GLOW ( DELUXE ).
The product name has 6 different spans so we want to print the product name "GOLDEN GLOW ( DELUXE )", i.e including the all the spans so I have tried to use the and multiple time inside the but it didn't work. Below is the XPath:



//*[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') contains(@class, 'no-mobile') ]


Below is the HTML code:



<span class="m-shopping-cart-item-header-number">
(
<span id="itemNo-1" class="itemNo">3</span>
of
<span id="totalItems-1" class="totalItems">3</span>
)
<span class="itemTitleCopy no-mobile" id="itemTitleCopy-1">Golden Glow</span>
<span class="no-mobile">(</span>
<span class="sizeDescriptionTitle no-mobile" id="sizeDescriptionTitle-1">Deluxe</span>
<span class="no-mobile">)</span>
</span>




Update



Code trials:



WebElement checkoutShippingProdName = new WebDriverWait(getDriver(), 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='m-shopping-cart-item-header-number']"))); 
String shipProdElementHtml = checkoutShippingProdName.getAttribute("innerHTML");
String shipProdElementHtmlHtmlSplit = shipProdElementHtml.split("span>");
String currentProd = shipProdElementHtmlHtmlSplit[shipProdElementHtmlHtmlSplit.length -1];
currentProd = StringEscapeUtils.unescapeHtml4(StringUtils.trim(currentProd));
System.out.println("The Product Name is:" + currentProd);









share|improve this question




















  • 1





    Edit your question with HTML sample, your current XPath, current output, desired output

    – Andersson
    Jan 3 at 12:37











  • I think you are missing and operator before last cotains.

    – Amrendra Kumar
    Jan 3 at 12:41











  • Post XML which will help us to find the problem.

    – Amrendra Kumar
    Jan 3 at 12:43











  • I want to prinit the product name i.e Golden Glow ( Deluxe ) ignoring the (3 of 3) so to get this I am trying to use the AND operatier to write the Xptah //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') and contains(@class, 'no-mobile') ]

    – user3538483
    Jan 3 at 12:58











  • And it didn't work i am able to use and operatior only once i.e //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') ] till this I am able to identify the Elment but if I use the all the and operator 3 times I am not able to identify elment.

    – user3538483
    Jan 3 at 12:59














1












1








1








The page contains a Product name-(3 OF 3) GOLDEN GLOW ( DELUXE ).
The product name has 6 different spans so we want to print the product name "GOLDEN GLOW ( DELUXE )", i.e including the all the spans so I have tried to use the and multiple time inside the but it didn't work. Below is the XPath:



//*[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') contains(@class, 'no-mobile') ]


Below is the HTML code:



<span class="m-shopping-cart-item-header-number">
(
<span id="itemNo-1" class="itemNo">3</span>
of
<span id="totalItems-1" class="totalItems">3</span>
)
<span class="itemTitleCopy no-mobile" id="itemTitleCopy-1">Golden Glow</span>
<span class="no-mobile">(</span>
<span class="sizeDescriptionTitle no-mobile" id="sizeDescriptionTitle-1">Deluxe</span>
<span class="no-mobile">)</span>
</span>




Update



Code trials:



WebElement checkoutShippingProdName = new WebDriverWait(getDriver(), 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='m-shopping-cart-item-header-number']"))); 
String shipProdElementHtml = checkoutShippingProdName.getAttribute("innerHTML");
String shipProdElementHtmlHtmlSplit = shipProdElementHtml.split("span>");
String currentProd = shipProdElementHtmlHtmlSplit[shipProdElementHtmlHtmlSplit.length -1];
currentProd = StringEscapeUtils.unescapeHtml4(StringUtils.trim(currentProd));
System.out.println("The Product Name is:" + currentProd);









share|improve this question
















The page contains a Product name-(3 OF 3) GOLDEN GLOW ( DELUXE ).
The product name has 6 different spans so we want to print the product name "GOLDEN GLOW ( DELUXE )", i.e including the all the spans so I have tried to use the and multiple time inside the but it didn't work. Below is the XPath:



//*[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') contains(@class, 'no-mobile') ]


Below is the HTML code:



<span class="m-shopping-cart-item-header-number">
(
<span id="itemNo-1" class="itemNo">3</span>
of
<span id="totalItems-1" class="totalItems">3</span>
)
<span class="itemTitleCopy no-mobile" id="itemTitleCopy-1">Golden Glow</span>
<span class="no-mobile">(</span>
<span class="sizeDescriptionTitle no-mobile" id="sizeDescriptionTitle-1">Deluxe</span>
<span class="no-mobile">)</span>
</span>




Update



Code trials:



WebElement checkoutShippingProdName = new WebDriverWait(getDriver(), 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='m-shopping-cart-item-header-number']"))); 
String shipProdElementHtml = checkoutShippingProdName.getAttribute("innerHTML");
String shipProdElementHtmlHtmlSplit = shipProdElementHtml.split("span>");
String currentProd = shipProdElementHtmlHtmlSplit[shipProdElementHtmlHtmlSplit.length -1];
currentProd = StringEscapeUtils.unescapeHtml4(StringUtils.trim(currentProd));
System.out.println("The Product Name is:" + currentProd);






java selenium selenium-webdriver xpath webdriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 18:52









DebanjanB

45.7k134688




45.7k134688










asked Jan 3 at 12:34









user3538483user3538483

78229




78229








  • 1





    Edit your question with HTML sample, your current XPath, current output, desired output

    – Andersson
    Jan 3 at 12:37











  • I think you are missing and operator before last cotains.

    – Amrendra Kumar
    Jan 3 at 12:41











  • Post XML which will help us to find the problem.

    – Amrendra Kumar
    Jan 3 at 12:43











  • I want to prinit the product name i.e Golden Glow ( Deluxe ) ignoring the (3 of 3) so to get this I am trying to use the AND operatier to write the Xptah //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') and contains(@class, 'no-mobile') ]

    – user3538483
    Jan 3 at 12:58











  • And it didn't work i am able to use and operatior only once i.e //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') ] till this I am able to identify the Elment but if I use the all the and operator 3 times I am not able to identify elment.

    – user3538483
    Jan 3 at 12:59














  • 1





    Edit your question with HTML sample, your current XPath, current output, desired output

    – Andersson
    Jan 3 at 12:37











  • I think you are missing and operator before last cotains.

    – Amrendra Kumar
    Jan 3 at 12:41











  • Post XML which will help us to find the problem.

    – Amrendra Kumar
    Jan 3 at 12:43











  • I want to prinit the product name i.e Golden Glow ( Deluxe ) ignoring the (3 of 3) so to get this I am trying to use the AND operatier to write the Xptah //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') and contains(@class, 'no-mobile') ]

    – user3538483
    Jan 3 at 12:58











  • And it didn't work i am able to use and operatior only once i.e //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') ] till this I am able to identify the Elment but if I use the all the and operator 3 times I am not able to identify elment.

    – user3538483
    Jan 3 at 12:59








1




1





Edit your question with HTML sample, your current XPath, current output, desired output

– Andersson
Jan 3 at 12:37





Edit your question with HTML sample, your current XPath, current output, desired output

– Andersson
Jan 3 at 12:37













I think you are missing and operator before last cotains.

– Amrendra Kumar
Jan 3 at 12:41





I think you are missing and operator before last cotains.

– Amrendra Kumar
Jan 3 at 12:41













Post XML which will help us to find the problem.

– Amrendra Kumar
Jan 3 at 12:43





Post XML which will help us to find the problem.

– Amrendra Kumar
Jan 3 at 12:43













I want to prinit the product name i.e Golden Glow ( Deluxe ) ignoring the (3 of 3) so to get this I am trying to use the AND operatier to write the Xptah //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') and contains(@class, 'no-mobile') ]

– user3538483
Jan 3 at 12:58





I want to prinit the product name i.e Golden Glow ( Deluxe ) ignoring the (3 of 3) so to get this I am trying to use the AND operatier to write the Xptah //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') and contains(@class, 'sizeDescriptionTitle no-mobile') and contains(@class, 'no-mobile') ]

– user3538483
Jan 3 at 12:58













And it didn't work i am able to use and operatior only once i.e //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') ] till this I am able to identify the Elment but if I use the all the and operator 3 times I am not able to identify elment.

– user3538483
Jan 3 at 12:59





And it didn't work i am able to use and operatior only once i.e //span[@class='itemTitleCopy no-mobile' and contains(@class, 'no-mobile') ] till this I am able to identify the Elment but if I use the all the and operator 3 times I am not able to identify elment.

– user3538483
Jan 3 at 12:59












5 Answers
5






active

oldest

votes


















2














'//span[@class="totalItems"]/following-sibling::span'


should select all span nodes after span with class="totalItems". There might be different approaches of extracting required text content depends on Selenium binding.



This is Python code to get required output:



text = " ".join([span.text for span in driver.find_elements_by_xpath('//span[@class="totalItems"]/following-sibling::span')])
print(text)
# 'Golden Glow(Deluxe)'





share|improve this answer

































    2














    As @Michael Kay has answered what you need is to use to or operator!



    You can do this with the findElements Selenium.



    It should look something like this:



    driver.findElements(By.xpath("//*[@class='itemTitleCopy no-mobile' or contains(@class, 'no-mobile') or contains(@class, 'sizeDescriptionTitle no-mobile')]"))


    This returns a list of WebElements now you can iterate through them and join the text to create your desired string of "GOLDEN GLOW ( DELUXE )".



    All the credit is to @Michael Kay I just gave you the example...






    share|improve this answer





















    • 1





      Well, you are close. The ( and ) seems not getting included.

      – DebanjanB
      Jan 3 at 17:19











    • Just removed it good aye!

      – Moshe Slavin
      Jan 3 at 17:20



















    1














    You seem to be confused about the meaning of and and or. The and operator within a predicate means that both conditions must be true: it's more restrictive, so in general less data will be selected. The or operator means either condition must be true: it's more liberal, so more data will be selected.



    You seem to be thinking of "and" as meaning "union" - select X and (also select) Y. That's never its meaning in boolean logic.






    share|improve this answer































      0














      Use this:



      //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]


      Hope it will solve.






      share|improve this answer
























      • No it's not working

        – user3538483
        Jan 3 at 13:03











      • see this link: xpather.com/2T1wyR8S

        – Amrendra Kumar
        Jan 3 at 13:03











      • org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]' is not a valid XPath expression.

        – user3538483
        Jan 3 at 13:10











      • This is XPath 2.0 syntax which is not supported by Selenium

        – Andersson
        Jan 3 at 13:17



















      0














      To extract the text Golden Glow ( Deluxe ) you can use the following Locator Strategy:





      • Using XPath:



        String myString = driver.findElement(By.xpath("//span[@class='m-shopping-cart-item-header-number']")).getText();
        String parts = myString.split("?<=)");
        System.out.println(parts[1]);







      share|improve this answer


























      • Tried this way but not able to print, can you please help me if I am missing anything

        – user3538483
        Jan 3 at 13:32











      • Checkout my updated answer and let me know the status

        – DebanjanB
        Jan 3 at 17:15











      • @user3538483 Changed the solution, any update?

        – DebanjanB
        Jan 4 at 12:18












      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%2f54022391%2fhow-to-write-an-xpath-using-and-operator-to-add-multiple-spans-in-a-single-xpath%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      '//span[@class="totalItems"]/following-sibling::span'


      should select all span nodes after span with class="totalItems". There might be different approaches of extracting required text content depends on Selenium binding.



      This is Python code to get required output:



      text = " ".join([span.text for span in driver.find_elements_by_xpath('//span[@class="totalItems"]/following-sibling::span')])
      print(text)
      # 'Golden Glow(Deluxe)'





      share|improve this answer






























        2














        '//span[@class="totalItems"]/following-sibling::span'


        should select all span nodes after span with class="totalItems". There might be different approaches of extracting required text content depends on Selenium binding.



        This is Python code to get required output:



        text = " ".join([span.text for span in driver.find_elements_by_xpath('//span[@class="totalItems"]/following-sibling::span')])
        print(text)
        # 'Golden Glow(Deluxe)'





        share|improve this answer




























          2












          2








          2







          '//span[@class="totalItems"]/following-sibling::span'


          should select all span nodes after span with class="totalItems". There might be different approaches of extracting required text content depends on Selenium binding.



          This is Python code to get required output:



          text = " ".join([span.text for span in driver.find_elements_by_xpath('//span[@class="totalItems"]/following-sibling::span')])
          print(text)
          # 'Golden Glow(Deluxe)'





          share|improve this answer















          '//span[@class="totalItems"]/following-sibling::span'


          should select all span nodes after span with class="totalItems". There might be different approaches of extracting required text content depends on Selenium binding.



          This is Python code to get required output:



          text = " ".join([span.text for span in driver.find_elements_by_xpath('//span[@class="totalItems"]/following-sibling::span')])
          print(text)
          # 'Golden Glow(Deluxe)'






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 3 at 13:10

























          answered Jan 3 at 13:03









          AnderssonAndersson

          39.1k113669




          39.1k113669

























              2














              As @Michael Kay has answered what you need is to use to or operator!



              You can do this with the findElements Selenium.



              It should look something like this:



              driver.findElements(By.xpath("//*[@class='itemTitleCopy no-mobile' or contains(@class, 'no-mobile') or contains(@class, 'sizeDescriptionTitle no-mobile')]"))


              This returns a list of WebElements now you can iterate through them and join the text to create your desired string of "GOLDEN GLOW ( DELUXE )".



              All the credit is to @Michael Kay I just gave you the example...






              share|improve this answer





















              • 1





                Well, you are close. The ( and ) seems not getting included.

                – DebanjanB
                Jan 3 at 17:19











              • Just removed it good aye!

                – Moshe Slavin
                Jan 3 at 17:20
















              2














              As @Michael Kay has answered what you need is to use to or operator!



              You can do this with the findElements Selenium.



              It should look something like this:



              driver.findElements(By.xpath("//*[@class='itemTitleCopy no-mobile' or contains(@class, 'no-mobile') or contains(@class, 'sizeDescriptionTitle no-mobile')]"))


              This returns a list of WebElements now you can iterate through them and join the text to create your desired string of "GOLDEN GLOW ( DELUXE )".



              All the credit is to @Michael Kay I just gave you the example...






              share|improve this answer





















              • 1





                Well, you are close. The ( and ) seems not getting included.

                – DebanjanB
                Jan 3 at 17:19











              • Just removed it good aye!

                – Moshe Slavin
                Jan 3 at 17:20














              2












              2








              2







              As @Michael Kay has answered what you need is to use to or operator!



              You can do this with the findElements Selenium.



              It should look something like this:



              driver.findElements(By.xpath("//*[@class='itemTitleCopy no-mobile' or contains(@class, 'no-mobile') or contains(@class, 'sizeDescriptionTitle no-mobile')]"))


              This returns a list of WebElements now you can iterate through them and join the text to create your desired string of "GOLDEN GLOW ( DELUXE )".



              All the credit is to @Michael Kay I just gave you the example...






              share|improve this answer















              As @Michael Kay has answered what you need is to use to or operator!



              You can do this with the findElements Selenium.



              It should look something like this:



              driver.findElements(By.xpath("//*[@class='itemTitleCopy no-mobile' or contains(@class, 'no-mobile') or contains(@class, 'sizeDescriptionTitle no-mobile')]"))


              This returns a list of WebElements now you can iterate through them and join the text to create your desired string of "GOLDEN GLOW ( DELUXE )".



              All the credit is to @Michael Kay I just gave you the example...







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 3 at 17:19

























              answered Jan 3 at 17:12









              Moshe SlavinMoshe Slavin

              2,44741126




              2,44741126








              • 1





                Well, you are close. The ( and ) seems not getting included.

                – DebanjanB
                Jan 3 at 17:19











              • Just removed it good aye!

                – Moshe Slavin
                Jan 3 at 17:20














              • 1





                Well, you are close. The ( and ) seems not getting included.

                – DebanjanB
                Jan 3 at 17:19











              • Just removed it good aye!

                – Moshe Slavin
                Jan 3 at 17:20








              1




              1





              Well, you are close. The ( and ) seems not getting included.

              – DebanjanB
              Jan 3 at 17:19





              Well, you are close. The ( and ) seems not getting included.

              – DebanjanB
              Jan 3 at 17:19













              Just removed it good aye!

              – Moshe Slavin
              Jan 3 at 17:20





              Just removed it good aye!

              – Moshe Slavin
              Jan 3 at 17:20











              1














              You seem to be confused about the meaning of and and or. The and operator within a predicate means that both conditions must be true: it's more restrictive, so in general less data will be selected. The or operator means either condition must be true: it's more liberal, so more data will be selected.



              You seem to be thinking of "and" as meaning "union" - select X and (also select) Y. That's never its meaning in boolean logic.






              share|improve this answer




























                1














                You seem to be confused about the meaning of and and or. The and operator within a predicate means that both conditions must be true: it's more restrictive, so in general less data will be selected. The or operator means either condition must be true: it's more liberal, so more data will be selected.



                You seem to be thinking of "and" as meaning "union" - select X and (also select) Y. That's never its meaning in boolean logic.






                share|improve this answer


























                  1












                  1








                  1







                  You seem to be confused about the meaning of and and or. The and operator within a predicate means that both conditions must be true: it's more restrictive, so in general less data will be selected. The or operator means either condition must be true: it's more liberal, so more data will be selected.



                  You seem to be thinking of "and" as meaning "union" - select X and (also select) Y. That's never its meaning in boolean logic.






                  share|improve this answer













                  You seem to be confused about the meaning of and and or. The and operator within a predicate means that both conditions must be true: it's more restrictive, so in general less data will be selected. The or operator means either condition must be true: it's more liberal, so more data will be selected.



                  You seem to be thinking of "and" as meaning "union" - select X and (also select) Y. That's never its meaning in boolean logic.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 3 at 15:44









                  Michael KayMichael Kay

                  112k663119




                  112k663119























                      0














                      Use this:



                      //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]


                      Hope it will solve.






                      share|improve this answer
























                      • No it's not working

                        – user3538483
                        Jan 3 at 13:03











                      • see this link: xpather.com/2T1wyR8S

                        – Amrendra Kumar
                        Jan 3 at 13:03











                      • org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]' is not a valid XPath expression.

                        – user3538483
                        Jan 3 at 13:10











                      • This is XPath 2.0 syntax which is not supported by Selenium

                        – Andersson
                        Jan 3 at 13:17
















                      0














                      Use this:



                      //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]


                      Hope it will solve.






                      share|improve this answer
























                      • No it's not working

                        – user3538483
                        Jan 3 at 13:03











                      • see this link: xpather.com/2T1wyR8S

                        – Amrendra Kumar
                        Jan 3 at 13:03











                      • org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]' is not a valid XPath expression.

                        – user3538483
                        Jan 3 at 13:10











                      • This is XPath 2.0 syntax which is not supported by Selenium

                        – Andersson
                        Jan 3 at 13:17














                      0












                      0








                      0







                      Use this:



                      //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]


                      Hope it will solve.






                      share|improve this answer













                      Use this:



                      //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]


                      Hope it will solve.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 3 at 12:59









                      Amrendra KumarAmrendra Kumar

                      1,2391312




                      1,2391312













                      • No it's not working

                        – user3538483
                        Jan 3 at 13:03











                      • see this link: xpather.com/2T1wyR8S

                        – Amrendra Kumar
                        Jan 3 at 13:03











                      • org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]' is not a valid XPath expression.

                        – user3538483
                        Jan 3 at 13:10











                      • This is XPath 2.0 syntax which is not supported by Selenium

                        – Andersson
                        Jan 3 at 13:17



















                      • No it's not working

                        – user3538483
                        Jan 3 at 13:03











                      • see this link: xpather.com/2T1wyR8S

                        – Amrendra Kumar
                        Jan 3 at 13:03











                      • org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]' is not a valid XPath expression.

                        – user3538483
                        Jan 3 at 13:10











                      • This is XPath 2.0 syntax which is not supported by Selenium

                        – Andersson
                        Jan 3 at 13:17

















                      No it's not working

                      – user3538483
                      Jan 3 at 13:03





                      No it's not working

                      – user3538483
                      Jan 3 at 13:03













                      see this link: xpather.com/2T1wyR8S

                      – Amrendra Kumar
                      Jan 3 at 13:03





                      see this link: xpather.com/2T1wyR8S

                      – Amrendra Kumar
                      Jan 3 at 13:03













                      org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]' is not a valid XPath expression.

                      – user3538483
                      Jan 3 at 13:10





                      org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]' is not a valid XPath expression.

                      – user3538483
                      Jan 3 at 13:10













                      This is XPath 2.0 syntax which is not supported by Selenium

                      – Andersson
                      Jan 3 at 13:17





                      This is XPath 2.0 syntax which is not supported by Selenium

                      – Andersson
                      Jan 3 at 13:17











                      0














                      To extract the text Golden Glow ( Deluxe ) you can use the following Locator Strategy:





                      • Using XPath:



                        String myString = driver.findElement(By.xpath("//span[@class='m-shopping-cart-item-header-number']")).getText();
                        String parts = myString.split("?<=)");
                        System.out.println(parts[1]);







                      share|improve this answer


























                      • Tried this way but not able to print, can you please help me if I am missing anything

                        – user3538483
                        Jan 3 at 13:32











                      • Checkout my updated answer and let me know the status

                        – DebanjanB
                        Jan 3 at 17:15











                      • @user3538483 Changed the solution, any update?

                        – DebanjanB
                        Jan 4 at 12:18
















                      0














                      To extract the text Golden Glow ( Deluxe ) you can use the following Locator Strategy:





                      • Using XPath:



                        String myString = driver.findElement(By.xpath("//span[@class='m-shopping-cart-item-header-number']")).getText();
                        String parts = myString.split("?<=)");
                        System.out.println(parts[1]);







                      share|improve this answer


























                      • Tried this way but not able to print, can you please help me if I am missing anything

                        – user3538483
                        Jan 3 at 13:32











                      • Checkout my updated answer and let me know the status

                        – DebanjanB
                        Jan 3 at 17:15











                      • @user3538483 Changed the solution, any update?

                        – DebanjanB
                        Jan 4 at 12:18














                      0












                      0








                      0







                      To extract the text Golden Glow ( Deluxe ) you can use the following Locator Strategy:





                      • Using XPath:



                        String myString = driver.findElement(By.xpath("//span[@class='m-shopping-cart-item-header-number']")).getText();
                        String parts = myString.split("?<=)");
                        System.out.println(parts[1]);







                      share|improve this answer















                      To extract the text Golden Glow ( Deluxe ) you can use the following Locator Strategy:





                      • Using XPath:



                        String myString = driver.findElement(By.xpath("//span[@class='m-shopping-cart-item-header-number']")).getText();
                        String parts = myString.split("?<=)");
                        System.out.println(parts[1]);








                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jan 4 at 12:17

























                      answered Jan 3 at 13:02









                      DebanjanBDebanjanB

                      45.7k134688




                      45.7k134688













                      • Tried this way but not able to print, can you please help me if I am missing anything

                        – user3538483
                        Jan 3 at 13:32











                      • Checkout my updated answer and let me know the status

                        – DebanjanB
                        Jan 3 at 17:15











                      • @user3538483 Changed the solution, any update?

                        – DebanjanB
                        Jan 4 at 12:18



















                      • Tried this way but not able to print, can you please help me if I am missing anything

                        – user3538483
                        Jan 3 at 13:32











                      • Checkout my updated answer and let me know the status

                        – DebanjanB
                        Jan 3 at 17:15











                      • @user3538483 Changed the solution, any update?

                        – DebanjanB
                        Jan 4 at 12:18

















                      Tried this way but not able to print, can you please help me if I am missing anything

                      – user3538483
                      Jan 3 at 13:32





                      Tried this way but not able to print, can you please help me if I am missing anything

                      – user3538483
                      Jan 3 at 13:32













                      Checkout my updated answer and let me know the status

                      – DebanjanB
                      Jan 3 at 17:15





                      Checkout my updated answer and let me know the status

                      – DebanjanB
                      Jan 3 at 17:15













                      @user3538483 Changed the solution, any update?

                      – DebanjanB
                      Jan 4 at 12:18





                      @user3538483 Changed the solution, any update?

                      – DebanjanB
                      Jan 4 at 12:18


















                      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%2f54022391%2fhow-to-write-an-xpath-using-and-operator-to-add-multiple-spans-in-a-single-xpath%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

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas

                      Can't read property showImagePicker of undefined in react native iOS