Can't get value of disabled field

I have been able to get the value of a React field using the get.attribute code listed below. I can’t seem to get the value from a disabled field. It is returning as null. I have googled for a while and actually read some topics on this forum, but nothing just yet seems to be working for me.

I am trying to get the value of the Description field (which is disabled) and verify that it matches an expected text.

HTML

Code

value = WebUI.getAttribute(findTestObject('Object Repository/Add Bill/Page/div_Accessorial_Description’), ‘value’)_

println('The value is: ’ + value)

WebUI.verifyMatch(value, ‘HAZARDOUS MATERIALS’, false)

Errors:

2019-10-24 14:02:36.868 ERROR c.k.k.core.keyword.internal.KeywordMain - Unable to verify match between actual text ‘null’ and expected text ‘HAZARDOUS MATERIALS’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘null’ and expected text ‘HAZARDOUS MATERIALS’ are not matched.

hello,

something like this
WebDriver driver = new ChromeDriver()
driver.get(“some page”)
JavascriptExecutor js = (JavascriptExecutor)driver;
String text = js.executeScript(“document.querySelector(‘CSS selectors’).disabled = false;”)

@mlilly

That’s not an HTML <input> element so it does not have a value attribute. It is a div-element where the content is stored inside it - it’s called its innerText.

You can retrieve innerText using WebUI.getText()

If you’d shown enough of the HTML, I could have written the CSS selector for you. (I see the parent div has an id, but it looks to be dynamic in which case it would cause you even more problems).

Thanks Russ, this is what worked for me…perfect!

value = WebUI.getText(findTestObject('Add Bill/Page/div_Accessorial_Description’))_

println('The value is: ’ + value)

WebUI.verifyMatch(value, ‘HAZARDOUS MATERIALS’, false)

1 Like