Using Selenium Webdriver to Retrieve the Value of an HTML Input

Selenium WebDriver get text from input field

This is the input element - you need to get the value attribute:

webDriver.findElement(By.id("inputTag")).getAttribute("value")

Get value of an input box using Selenium (Python)

Use this to get the value of the input element:

input.get_attribute('value')

Get current value of a webelement in selenium after clicking a button

It seems that although '20' is entered into the field, the "value" attribute still remains '0'.

Try this:

elem = driver.find_element_by_xpath("[YOUR_PATH_HERE]")

elem.get_attribute("innerHTML")

print(elem)

You could double click the field and copy the value.

from selenium.webdriver.common.action_chains import ActionChains
import pyperclip

elem = driver.find_element_by_xpath("[YOUR_PATH_HERE]")

actions = ActionChains(driver)

actions.double_click(elem).perform()

elem.send_keys(u'\ue009', 'c') # This is CONTROL + C

text = pyperclip.paste()

Selenium (Java): Retrieve value from disabled input text field

You can try via JavascriptExecutor :

Thread.sleep(3) // add a pause to wait until value of the element will be rendered
JavascriptExecutor je = (JavascriptExecutor) driver;
String script = "return document.getElementById('NameInputID').getAttribute('value');");
String value = je.executeScript(script);


Related Topics



Leave a reply



Submit