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












1















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




















  • 1





    Which Language Binding? Java/Python/C#?

    – DebanjanB
    Nov 18 '18 at 16:55
















1















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




















  • 1





    Which Language Binding? Java/Python/C#?

    – DebanjanB
    Nov 18 '18 at 16:55














1












1








1








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
















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















share|improve this question













share|improve this question




share|improve this question








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














  • 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












3 Answers
3






active

oldest

votes


















0














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
    Nov 19 '18 at 17:53



















0














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
    Nov 18 '18 at 18:54











  • Thank you so much.

    – Divya
    Nov 19 '18 at 17:55



















0














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
    Nov 19 '18 at 17:54











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%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









0














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
    Nov 19 '18 at 17:53
















0














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
    Nov 19 '18 at 17:53














0












0








0







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 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














  • 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













0














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
    Nov 18 '18 at 18:54











  • Thank you so much.

    – Divya
    Nov 19 '18 at 17:55
















0














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
    Nov 18 '18 at 18:54











  • Thank you so much.

    – Divya
    Nov 19 '18 at 17:55














0












0








0







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 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



















  • 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











0














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
    Nov 19 '18 at 17:54
















0














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
    Nov 19 '18 at 17:54














0












0








0







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 Nov 19 '18 at 10:20









psmaginpsmagin

150119




150119













  • 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





Thank you, I got it now.

– Divya
Nov 19 '18 at 17:54


















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%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()