Pablo
Pablo

Reputation: 15

Please, help to get a value for a webelement

I would like to ask the help - I need to get the value from WebElement 'input'. I tried general methods like getText(), but it doesn't work. Then I tried JavaScript in console and in console it works fine:

"document.evaluate('(//div[@id="CreateOrderBlock"]//input[@class="el-input__inner"])[3]',document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.value;"

But how to handle it in the test? (Selenium WebDriver + Java) How to convert it to int java? Maybe I need JavascriptExecutor , but in any case I would like to get an example. I tried like:

 String summValueString = (String)((JavascriptExecutor) driver).executeScript("document.evaluate('(//div[@id='CreateOrderBlock']//input[@class='el-input__inner'])[3]',document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.value;");
<div class="input el-input">
<!---->
<input autocomplete="off" type="text" rows="2" validateevent="true" class="el-input__inner">
<!---->
<!---->
<!---->
</div>

Thank you in advance

Upvotes: 1

Views: 130

Answers (1)

frianH
frianH

Reputation: 7563

To get the value of an input text, please use the .getAttribute("value") method instead of .getText().

Upvotes: 1

Related Questions