How to Get Value from a Disabled Text Field When the Value Is Not Present in Id or in Any Attribute Using Java in Selenium Webdriver

How to get value from a disabled text field when the value is not present in ID or in any attribute using Java in Selenium WebDriver

The value attribute stores the content of a tag, does not matter whether it is disabled or not. So, you can do it like this:

driver.findElement(By.id("write_element_id_here")).getAttribute("value");

this will return you the value of the element and then you can proceed with the rest. Hope it helps..

How to get the text from disabled textbox using selenium Webdriver?

The value attribute stores the content of a tag, does not matter whether it is disabled or not. So, you can do it like this:

driver.findElement(By.id("write_element_id_here")).getAttribute("value");

This will return you the value of the element and then you can proceed with the rest. Hope it helps..

How to getText from a disabled input field in Selenium Java

Try:

webElement.findElement(By.cssSelector("#endDate")).getAttribute("value")

Or:

webElement.findElement(By.cssSelector("#endDate")).getText()

You have to try it out. It depends on your special case. If these variants don't work, check if your selectors are correct.

If all of them didn't work, try to get the value over angular.element as below:

return (String) ((JavascriptExecutor) this.webDriver).executeScript("angular.element($('#endDate')).text()");

Get the value of disabled input using Selenium WebDriver

If you tag it like this -

<input disabled="true" id='data'>

Your code should be -

WebElement.getAttribute("disabled")

or

WebElement.getAttribute("id")

Make sure your code is correct.

For this tag -

<input id="j_idt93:j_idt93" type="text" disabled="disabled" maxlength="2000" value="Pārtraukts">

To get the value attribute -

String value = driver.findElement(By.id("j_idt93:j_idt93")).getAttribute("value");

value must be Pārtraukts

If this does not work, you may have to use the JavaScript executor -

String value =  (String)((JavascriptExecutor) driver).executeScript("JavaScript query in here to return the value", "");

Your query should be -

return document.getElementById("j_idt93:j_idt93").getAttribute("value");

How to find input field is readonly or not in using selenium webdriver with java

You can achieve this without having to execute JS, all you need to do is to get the DOM Attribute of the element which is "ReadOnly" this can be achieved using:

   WebElement readOnly = driver.findElementBy(locator);
Assert.assertTrue(readOnly.getAttribute("readOnly").equals("true"),"Element ReadOnly")

Hope this helps....

How to assert the text box is enabled or disabled

isEnabled()

As per the documentation isEnabled() method is defined as:

boolean isEnabled()

Description:
Is the element currently enabled or not? This will generally return true for everything but disabled input elements.

Returns:
True if the element is enabled, false otherwise.

So your code trial as element.isEnabled() was perfect to retrieve the status whether the element was enabled or not provided the element uniquely identified the node which you have provided within the question.

Alternative

As an alternative you can try to validate if the elelemt is present without the attribute disabled using the following solution:

try {
driver.findElement(By.xpath("//input[@class='textfield form-control servicefield invItem_dynamic_validation valid' and not(disabled)][@controlid='txtIPAddress']"));
System.out.println("Element is enabled");
} catch (NoSuchElementException e) {
System.out.println("Element is not enabled");
}

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