Reputation: 21
How can we get the value inside the value section in selenium
I need to retrieve Mr in a string present under value using selenium.
Since its not a free text so getText() is not working.
Upvotes: 0
Views: 8616
Reputation: 137
Use the get attribute method
value = driver.find_element(By.CLASS_NAME, 'title')
output = value.get_attribute("value")
Upvotes: 0
Reputation: 387
for python:
value=driver.find_element_by_id('tag ID')
print(value.text)
java:
System.out.println(driver.findElement(By.id('tag ID')).getText());
Upvotes: 1
Reputation: 4739
As per your requirement you can try this
it is your HTML code:
<input class="title" type="text" value="Mr">
Selenium code:
String textvalue=driver.findElement(By.xpath("//input[@value='Mr']")).getAttribute("value");
System.out.println(textvalue);
Upvotes: 1