I 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.
Asked
Active
Viewed 2,045 times
-1

Lipson T A
- 49
- 3
- 9
-
1Have you tried `driver.findElement(By.xpath("//input[@id = 'estimatedDepositRate']")).getAttribute("value")`? You need to use javascript? off: That is an input, not textBox – KunLun Jul 29 '19 at 10:28
-
there is no value property in the html Dom. Hence I didn't tried – Lipson T A Jul 29 '19 at 10:39
-
If you don't see it in `Inspect`, that doesn't mean there is no `value` property. – KunLun Jul 29 '19 at 10:46
-
1It is working...Thanks – Lipson T A Jul 29 '19 at 10:48
1 Answers
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.

Abhishek Dhoundiyal
- 1,359
- 1
- 12
- 19