I have been trying to get the first error message out of the following html in Fitnesse test using BrowserTest Slim fixture.
<div class="validation-errors">
<ul>
<li>Enter your code.</li>
<li>Enter your username.</li>
<li>Enter your password.</li>
</ul>
</div>
I have tried the following Xpath:
//div[@class='validation-errors']/ul/li[1]/text()
//div[@class='validation-errors']/ul/li[1]
//div[@class='validation-errors']/ul/li
The first xpath returns [null]
where as the second and third returns [0]
.
The expected result is Enter your code.
If I take li out completely
//div[@class='validation-errors']/ul
then it returns
[Enter your code.
Enter your username.
Enter your password.]
So either way my test fails where it looks only for the first error message. I have tried the xpath query on online Xpath testers where it seems to work as expected.
Here is a sample fitnesse test case:
|table template|try to login |
|open |https://my.url.com/login? |
|enter |@{code} |as |Code |
|enter |@{username}|as |Username |
|enter |@{password}|as |Password |
|click |Login |
|$message=|value of |xpath=//div[@class='validation-errors']/ul/li[1]|
|storyboard|browser test|
|try to login |
|code |username |password |message? |
| | | |Enter your code. |
May be I am missing something obvious but having tried to figure it out for few hours without any success I thought I will post this here in case some had a similar experience or can provide a solution to get the value of first <li>
out of the three.