Reputation:
I'm having problems getting the text contents of an input field. I seem to only be getting the things around it with the method I'm using.
Snippet from the page:
(It's a list of itemsincluding an input field in each row.)
The markup:
<ul class="budsjett budsjett--kompakt" id="sifobudsjett">
<li class="budsjett-post ng-isolate-scope ng-valid" id="SIFO_mat">
<div class="felt" >
<div class="felt-indre">
<div id="SIFO_mat-farge" class="sifo-farge farge-graa"></div>
<span class="budsjett-post-beskrivelse" >
<span tabindex="0" title="Vis hjelpetekst" role="button">
<span class="hjelpetekst-label" >Mat og drikke</span>
</span>
<span class="sifo-hjelp" aria-hidden="true"></span>
</span>
</span>
<span class="budsjett-post-verdi">
<span class="budsjett-post-verdi-endret" ng-show="!skrivebeskyttet" aria-hidden="false" style="">
<input id="SIFO_mat-input" name="SIFO_mat" type="number">
<span class="felt-enhet"><abbr id="SIFO_mat-enhet" title="kroner" translate=""><span class="ng-scope">kr</span></abbr></span>
</span>
</span>
</div>
</div>
</li>
The code:
List<WebElement> sifoliste = driver.findElement(By.id("sifobudsjett")).findElements(By.tagName("li"));
Result of first element: "Mat og drikke".
List<WebElement> sifoliste = driver.findElement(By.id("sifobudsjett")).findElements(By.tagName("input"));
Result of first element: ""
List<WebElement> sifoliste = driver.findElement(By.id("sifobudsjett")).findElements(By.className("budsjett-post-verdi-endret"));
Result of first element: "kr"
Any ideas?
Upvotes: 0
Views: 64
Reputation: 50899
The <input>
tag doesn't have text, what you see in the UI is kept in the value
attribute. It exists even if you can't see it in the html
driver.findElement(By.id("SIFO_mat-input")).getAttribute("value");
For all the <input>
s
List<WebElement> sifoliste = driver.findElement(By.id("sifobudsjett")).findElements(By.tagName("input"));
String text = sifoliste.get(0).getAttribute("value"); // 2790
Upvotes: 1
Reputation: 8686
Try
String inputValue = driver.findElement(By.tagName("input")).getAttribute("value");
Upvotes: 0