0

I am unable to get the data from the textbox using Selenium WebDriver. Here how the textbox element code looks like

<input aria-invalid="false" disabled="" id="2033323" type="text" class="MuiInputBase-input
MuiOutlinedInput-input Mui-disabled Mui-disabled" value="104" style="padding: 5px 7px;">

I see "104" in the textbox on UI and in my test I need to check, that this value is displayed. The id is unique, so I tried both By.xpath("//*[@id='2033323']") and By.id("2033323") to create the locator.

I can get values from e.g. "type" attribute via

driver.findElement(By.id("2033323")).getAttribute("type"));

But I get empty result if I try to get value from "value" attribute via

driver.findElement(By.id("2033323")).getAttribute("value"));
or
driver.findElement(By.id("2033323")).getCssValue("value"));

and .getText() is not suitable as there is no simple text there .

I even tried

JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
String temperature = (String)(jsExecutor.executeScript("return document.getElementById('2033323').value"));

and get an empty result.

1 Answer 1

0

Wait until the element is found and find the element using xpath and get the value

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='2033323']")));
driver.findElement(By.xpath("//input[@id='2033323']").getAttribute("value"));
Sign up to request clarification or add additional context in comments.

3 Comments

the problem is not the waiter, even in Debug I do not get the value
What error does the getText() throw?
Sorry, I formulated it incorrectly. No error, just an empty result, cause there is no simple text in tag, the value is contained only in the tag <input disabled id="2033323" .... value="some_value">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.