Unable to get the value in double quotes that is dynamically displayed using selenium xpath
I'm trying to get the value "19.5" which is dynamically displayed in below code using xpath in selenium. can anyone please help me with xpath to get the value 19.5, I'm new to selenium.
<li>
<label for="applyleave_leaveBalance">Leave Balance</label>
<div id="applyleave_leaveBalance" class>
"19.50"
<a href="#balance_details" data-toggle="modal" id="leaveBalance_details_link">view details</a>
</div>
</li>
java selenium xpath css-selectors webdriverwait
add a comment |
I'm trying to get the value "19.5" which is dynamically displayed in below code using xpath in selenium. can anyone please help me with xpath to get the value 19.5, I'm new to selenium.
<li>
<label for="applyleave_leaveBalance">Leave Balance</label>
<div id="applyleave_leaveBalance" class>
"19.50"
<a href="#balance_details" data-toggle="modal" id="leaveBalance_details_link">view details</a>
</div>
</li>
java selenium xpath css-selectors webdriverwait
1
Which Language Binding? Java/Python/C#?
– DebanjanB
Nov 18 '18 at 16:55
add a comment |
I'm trying to get the value "19.5" which is dynamically displayed in below code using xpath in selenium. can anyone please help me with xpath to get the value 19.5, I'm new to selenium.
<li>
<label for="applyleave_leaveBalance">Leave Balance</label>
<div id="applyleave_leaveBalance" class>
"19.50"
<a href="#balance_details" data-toggle="modal" id="leaveBalance_details_link">view details</a>
</div>
</li>
java selenium xpath css-selectors webdriverwait
I'm trying to get the value "19.5" which is dynamically displayed in below code using xpath in selenium. can anyone please help me with xpath to get the value 19.5, I'm new to selenium.
<li>
<label for="applyleave_leaveBalance">Leave Balance</label>
<div id="applyleave_leaveBalance" class>
"19.50"
<a href="#balance_details" data-toggle="modal" id="leaveBalance_details_link">view details</a>
</div>
</li>
<li>
<label for="applyleave_leaveBalance">Leave Balance</label>
<div id="applyleave_leaveBalance" class>
"19.50"
<a href="#balance_details" data-toggle="modal" id="leaveBalance_details_link">view details</a>
</div>
</li>
<li>
<label for="applyleave_leaveBalance">Leave Balance</label>
<div id="applyleave_leaveBalance" class>
"19.50"
<a href="#balance_details" data-toggle="modal" id="leaveBalance_details_link">view details</a>
</div>
</li>
java selenium xpath css-selectors webdriverwait
java selenium xpath css-selectors webdriverwait
edited Nov 19 '18 at 10:13
DebanjanB
41.8k83979
41.8k83979
asked Nov 18 '18 at 16:54
DivyaDivya
82
82
1
Which Language Binding? Java/Python/C#?
– DebanjanB
Nov 18 '18 at 16:55
add a comment |
1
Which Language Binding? Java/Python/C#?
– DebanjanB
Nov 18 '18 at 16:55
1
1
Which Language Binding? Java/Python/C#?
– DebanjanB
Nov 18 '18 at 16:55
Which Language Binding? Java/Python/C#?
– DebanjanB
Nov 18 '18 at 16:55
add a comment |
3 Answers
3
active
oldest
votes
A bit more of the outerHTML would have made the solution a bit easier. However as per the HTML you have provided to extract the value 19.5 you need to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='User']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
xpath
:
WebElement myElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(.,'Leave Balance')]//following::div[@id='applyleave_leaveBalance']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
1
Thank you, it worked. I 'm able to extract the value now.
– Divya
Nov 19 '18 at 17:53
add a comment |
please follow below steps
(1) take locator as
@FindBy(xpath="//div[@id='applyleave_leaveBalance']")
private WebElement balance;
public void printBalance()
{
System.out.println(balance.getText());
}
This will also extract the text of child link
– Andersson
Nov 18 '18 at 18:54
Thank you so much.
– Divya
Nov 19 '18 at 17:55
add a comment |
Try to use this
xpath="//div[@id='applyleave_leaveBalance']/text()[1]"
It will return first text node.
Thank you, I got it now.
– Divya
Nov 19 '18 at 17:54
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%2f53363297%2funable-to-get-the-value-in-double-quotes-that-is-dynamically-displayed-using-sel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
A bit more of the outerHTML would have made the solution a bit easier. However as per the HTML you have provided to extract the value 19.5 you need to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='User']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
xpath
:
WebElement myElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(.,'Leave Balance')]//following::div[@id='applyleave_leaveBalance']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
1
Thank you, it worked. I 'm able to extract the value now.
– Divya
Nov 19 '18 at 17:53
add a comment |
A bit more of the outerHTML would have made the solution a bit easier. However as per the HTML you have provided to extract the value 19.5 you need to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='User']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
xpath
:
WebElement myElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(.,'Leave Balance')]//following::div[@id='applyleave_leaveBalance']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
1
Thank you, it worked. I 'm able to extract the value now.
– Divya
Nov 19 '18 at 17:53
add a comment |
A bit more of the outerHTML would have made the solution a bit easier. However as per the HTML you have provided to extract the value 19.5 you need to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='User']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
xpath
:
WebElement myElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(.,'Leave Balance')]//following::div[@id='applyleave_leaveBalance']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
A bit more of the outerHTML would have made the solution a bit easier. However as per the HTML you have provided to extract the value 19.5 you need to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table[aria-label='User']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
xpath
:
WebElement myElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[contains(.,'Leave Balance')]//following::div[@id='applyleave_leaveBalance']")));
String myText = ((JavascriptExecutor)driver).executeScript('return arguments[0].firstChild.textContent;', myElement).toString();
answered Nov 19 '18 at 10:14
DebanjanBDebanjanB
41.8k83979
41.8k83979
1
Thank you, it worked. I 'm able to extract the value now.
– Divya
Nov 19 '18 at 17:53
add a comment |
1
Thank you, it worked. I 'm able to extract the value now.
– Divya
Nov 19 '18 at 17:53
1
1
Thank you, it worked. I 'm able to extract the value now.
– Divya
Nov 19 '18 at 17:53
Thank you, it worked. I 'm able to extract the value now.
– Divya
Nov 19 '18 at 17:53
add a comment |
please follow below steps
(1) take locator as
@FindBy(xpath="//div[@id='applyleave_leaveBalance']")
private WebElement balance;
public void printBalance()
{
System.out.println(balance.getText());
}
This will also extract the text of child link
– Andersson
Nov 18 '18 at 18:54
Thank you so much.
– Divya
Nov 19 '18 at 17:55
add a comment |
please follow below steps
(1) take locator as
@FindBy(xpath="//div[@id='applyleave_leaveBalance']")
private WebElement balance;
public void printBalance()
{
System.out.println(balance.getText());
}
This will also extract the text of child link
– Andersson
Nov 18 '18 at 18:54
Thank you so much.
– Divya
Nov 19 '18 at 17:55
add a comment |
please follow below steps
(1) take locator as
@FindBy(xpath="//div[@id='applyleave_leaveBalance']")
private WebElement balance;
public void printBalance()
{
System.out.println(balance.getText());
}
please follow below steps
(1) take locator as
@FindBy(xpath="//div[@id='applyleave_leaveBalance']")
private WebElement balance;
public void printBalance()
{
System.out.println(balance.getText());
}
answered Nov 18 '18 at 17:34
HarshitHarshit
41
41
This will also extract the text of child link
– Andersson
Nov 18 '18 at 18:54
Thank you so much.
– Divya
Nov 19 '18 at 17:55
add a comment |
This will also extract the text of child link
– Andersson
Nov 18 '18 at 18:54
Thank you so much.
– Divya
Nov 19 '18 at 17:55
This will also extract the text of child link
– Andersson
Nov 18 '18 at 18:54
This will also extract the text of child link
– Andersson
Nov 18 '18 at 18:54
Thank you so much.
– Divya
Nov 19 '18 at 17:55
Thank you so much.
– Divya
Nov 19 '18 at 17:55
add a comment |
Try to use this
xpath="//div[@id='applyleave_leaveBalance']/text()[1]"
It will return first text node.
Thank you, I got it now.
– Divya
Nov 19 '18 at 17:54
add a comment |
Try to use this
xpath="//div[@id='applyleave_leaveBalance']/text()[1]"
It will return first text node.
Thank you, I got it now.
– Divya
Nov 19 '18 at 17:54
add a comment |
Try to use this
xpath="//div[@id='applyleave_leaveBalance']/text()[1]"
It will return first text node.
Try to use this
xpath="//div[@id='applyleave_leaveBalance']/text()[1]"
It will return first text node.
answered Nov 19 '18 at 10:20
psmaginpsmagin
150119
150119
Thank you, I got it now.
– Divya
Nov 19 '18 at 17:54
add a comment |
Thank you, I got it now.
– Divya
Nov 19 '18 at 17:54
Thank you, I got it now.
– Divya
Nov 19 '18 at 17:54
Thank you, I got it now.
– Divya
Nov 19 '18 at 17:54
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%2f53363297%2funable-to-get-the-value-in-double-quotes-that-is-dynamically-displayed-using-sel%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
Which Language Binding? Java/Python/C#?
– DebanjanB
Nov 18 '18 at 16:55