Unable to get the value in double quotes that is dynamically displayed using selenium xpath











up vote
1
down vote

favorite












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>












share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Which Language Binding? Java/Python/C#?
    – DebanjanB
    2 days ago















up vote
1
down vote

favorite












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>












share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Which Language Binding? Java/Python/C#?
    – DebanjanB
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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>












share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









DebanjanB

35.3k73271




35.3k73271






New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Divya

82




82




New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Which Language Binding? Java/Python/C#?
    – DebanjanB
    2 days ago














  • 1




    Which Language Binding? Java/Python/C#?
    – DebanjanB
    2 days ago








1




1




Which Language Binding? Java/Python/C#?
– DebanjanB
2 days ago




Which Language Binding? Java/Python/C#?
– DebanjanB
2 days ago












3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










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();







share|improve this answer

















  • 1




    Thank you, it worked. I 'm able to extract the value now.
    – Divya
    yesterday


















up vote
0
down vote













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());
}





share|improve this answer





















  • This will also extract the text of child link
    – Andersson
    2 days ago










  • Thank you so much.
    – Divya
    yesterday


















up vote
0
down vote













Try to use this



xpath="//div[@id='applyleave_leaveBalance']/text()[1]"


It will return first text node.






share|improve this answer





















  • Thank you, I got it now.
    – Divya
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Divya is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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








up vote
0
down vote



accepted










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();







share|improve this answer

















  • 1




    Thank you, it worked. I 'm able to extract the value now.
    – Divya
    yesterday















up vote
0
down vote



accepted










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();







share|improve this answer

















  • 1




    Thank you, it worked. I 'm able to extract the value now.
    – Divya
    yesterday













up vote
0
down vote



accepted







up vote
0
down vote



accepted






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();







share|improve this answer












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();








share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









DebanjanB

35.3k73271




35.3k73271








  • 1




    Thank you, it worked. I 'm able to extract the value now.
    – Divya
    yesterday














  • 1




    Thank you, it worked. I 'm able to extract the value now.
    – Divya
    yesterday








1




1




Thank you, it worked. I 'm able to extract the value now.
– Divya
yesterday




Thank you, it worked. I 'm able to extract the value now.
– Divya
yesterday












up vote
0
down vote













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());
}





share|improve this answer





















  • This will also extract the text of child link
    – Andersson
    2 days ago










  • Thank you so much.
    – Divya
    yesterday















up vote
0
down vote













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());
}





share|improve this answer





















  • This will also extract the text of child link
    – Andersson
    2 days ago










  • Thank you so much.
    – Divya
    yesterday













up vote
0
down vote










up vote
0
down vote









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());
}





share|improve this answer












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());
}






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Harshit

41




41












  • This will also extract the text of child link
    – Andersson
    2 days ago










  • Thank you so much.
    – Divya
    yesterday


















  • This will also extract the text of child link
    – Andersson
    2 days ago










  • Thank you so much.
    – Divya
    yesterday
















This will also extract the text of child link
– Andersson
2 days ago




This will also extract the text of child link
– Andersson
2 days ago












Thank you so much.
– Divya
yesterday




Thank you so much.
– Divya
yesterday










up vote
0
down vote













Try to use this



xpath="//div[@id='applyleave_leaveBalance']/text()[1]"


It will return first text node.






share|improve this answer





















  • Thank you, I got it now.
    – Divya
    yesterday















up vote
0
down vote













Try to use this



xpath="//div[@id='applyleave_leaveBalance']/text()[1]"


It will return first text node.






share|improve this answer





















  • Thank you, I got it now.
    – Divya
    yesterday













up vote
0
down vote










up vote
0
down vote









Try to use this



xpath="//div[@id='applyleave_leaveBalance']/text()[1]"


It will return first text node.






share|improve this answer












Try to use this



xpath="//div[@id='applyleave_leaveBalance']/text()[1]"


It will return first text node.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









psmagin

130119




130119












  • Thank you, I got it now.
    – Divya
    yesterday


















  • Thank you, I got it now.
    – Divya
    yesterday
















Thank you, I got it now.
– Divya
yesterday




Thank you, I got it now.
– Divya
yesterday










Divya is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Divya is a new contributor. Be nice, and check out our Code of Conduct.













Divya is a new contributor. Be nice, and check out our Code of Conduct.












Divya is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














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





















































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

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$