-1

enter image description hereI wanted to get the text inside the input tag which is not available in my HTML. So I have to use JS for getting the value. But I am getting null as the result when running in eclipse. I have added the HTML and Selenium code in the below screenshot.

4
  • 1
    Have you tried driver.findElement(By.xpath("//input[@id = 'estimatedDepositRate']")).getAttribute("value")? You need to use javascript? off: That is an input, not textBox Commented Jul 29, 2019 at 10:28
  • there is no value property in the html Dom. Hence I didn't tried Commented Jul 29, 2019 at 10:39
  • If you don't see it in Inspect, that doesn't mean there is no value property. Commented Jul 29, 2019 at 10:46
  • 1
    It is working...Thanks Commented Jul 29, 2019 at 10:48

1 Answer 1

1

In Javascript:

document.getElementById("estimatedDepositRate").value;

This can be achieve in selenium using JavascriptExecutor :

String estimatedDepositRate  = ((JavascriptExecutor) driver).executeScript("return document.getElementById("estimatedDepositRate").value");

Normal Code:

driver.findElement(By.id("estimatedDepositRate")).getAttribute("value")

Note: Kindly cast the estimatedDepositRate value to String if you get any error.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.