How to write an XPath using AND Operator to add multiple spans in a single XPath?
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
java selenium selenium-webdriver xpath webdriver
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
|
show 1 more comment
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
|
show 1 more comment
5 Answers
5
active
oldest
votes
'//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)'
add a comment |
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...
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
add a comment |
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.
add a comment |
Use this:
//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]
Hope it will solve.
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
add a comment |
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]);
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
'//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)'
add a comment |
'//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)'
add a comment |
'//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)'
'//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)'
edited Jan 3 at 13:10
answered Jan 3 at 13:03
AnderssonAndersson
39.1k113669
39.1k113669
add a comment |
add a comment |
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...
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
add a comment |
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...
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
add a comment |
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...
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...
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 3 at 15:44
Michael KayMichael Kay
112k663119
112k663119
add a comment |
add a comment |
Use this:
//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]
Hope it will solve.
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
add a comment |
Use this:
//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]
Hope it will solve.
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
add a comment |
Use this:
//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]
Hope it will solve.
Use this:
//*[@class=('itemTitleCopy no-mobile','sizeDescriptionTitle no-mobile','no-mobile')]
Hope it will solve.
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
add a comment |
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
add a comment |
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]);
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
add a comment |
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]);
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
add a comment |
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]);
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]);
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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