I am trying get value or text from element, but it is not working. Kindly help me in this. Below is the path and Web Element.
Link: https://www.tcsion.com/OnlineAssessment/ScientificCalculator/Calculator.html
Element:
<input id="keyPad_UserInput" class="keyPad_TextBox" maxlength="30" readonly="" type="text">
You can use following code to get value from textfield.
driver.findElement(By.id("keyPad_UserInput")).click();
String text=driver.findElement(By.id("keyPad_UserInput")).getText();
System.out.println(text);
Try this; driver.findElement(By.id("keyPad_UserInput")).getAttribute("value")
You can use javascript executor to get value value from input field.
String return_value = (String) js.executeScript("return document.getElementById('keyPad_UserInput').value");
hope this help !
Use the below code,you will get the text entered in the field.
driver.findElement(By.xpath(".//*[@id='keyPad_btn2']")).click();
WebElement firstName = driver.findElement(By.xpath(".//*[@id='keyPad_btn2']"));
String value = firstName.getText();
System.out.println(value);
The Input Type Is Readbleonly you will get Data By using getAttribute("value")
method Only
driver.get("https://www.tcsion.com/OnlineAssessment/ScientificCalculator/Calculator.html");
System.out.println(" Page");
Thread.sleep(3000);
WebElement ele = driver.findElement(By.xpath("//input[@id='keyPad_UserInput']"));
System.out.println("value using getAttribute ::"+ele.getAttribute("value"));
System.out.println("value using getText::"+ ele.getText()); //its return empty or null
OutPut :
value using getAttribute :: 0
value using getText ::
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.