Reputation: 123
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.
Upvotes: 0
Views: 82
Reputation: 38
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"));
Upvotes: 0