Dheeraj Singh
Dheeraj Singh

Reputation: 21

How to get the value from a tag in Selenium

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

Answers (3)

sule mohammed
sule mohammed

Reputation: 137

Use the get attribute method

value = driver.find_element(By.CLASS_NAME, 'title')
output = value.get_attribute("value")

Upvotes: 0

Kumar S
Kumar S

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

iamsankalp89
iamsankalp89

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

Related Questions