I'm working with a DOM
node
<input type = "form-control" type="text" data-bind="textInput: EnterpriseId" disabled autocomplete="off">
How can I get it's value? I'm struggling since element.getText()
does not work and return blank.
Any suggestions would be of great help.
The Selenium WebDriver interface has predefined the getText() method, which helps retrieve the text for a specific web element. This method gets the visible, inner text (which is not hidden by CSS) of the web-element.
We can get text from a webelement with Selenium webdriver. The getText() methods obtains the innerText of an element. It fetches the text of an element which is visible along with its sub elements. It ignores the trailing and leading spaces.
try this
WebElement element= driver.findElement(By.id("id value"));
String val=element.getAttribute("innerText")
You can go to your browser -> open developer tools -> inspect element you want to take attribute from -> click Properties
-> check if that value is in InnerText
Then do as it is mentioned in above comments:
element_locator.get_attribute('InnerText')
This input tag is disabled, hence element.getText()
return blank val.
Use element.getAttribute("textContent")
instead. Hope this will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With