Selenide throws "ElementNotFound", but not always

330 views
Skip to first unread message

Dmitry Katsubo

unread,
Dec 12, 2014, 6:26:42 AM12/12/14
to sele...@googlegroups.com
Dear Selenide users/developers,

I have a strange issue, which I cannot explain. Maybe somebody can give a hint how to approach it the best.

The Java code is meant to wait until the given element becomes visible (it may not exist at the moment when this line is executed):

$(By.xpath("//table[@id='overview']/tbody/tr[td[contains(@class, 'status')]/a='SEQLCOMP-94684']")).waitUntil(visible, 10000);

The code is executed in two environments:
  1. Windows7 x64, Firefox v31
  2. Linux x64, Firefox v31
both are running over Selenide v2.14.

Windows7 environment always works. I have never seen the problem like the issue below.
Linux environment sometimes fails. That is: in some cases Unit test running the code above succeeds, sometimes fails. The ratio is approx 50/50.

So I believe xPath is correct. I have also doublechecked that xPath matches a node in HTML, which was dumped together with screenshot (see attachment) using FirePath addon.

The stack trace is:

com.codeborne.selenide.ex.ElementNotFound: Element not found {By.xpath: //table[@id='overview']/tbody/tr[td[contains(@class, 'status')]/a='SEQLCOMP-94684']}
Expected: visible
Screenshot:
Screenshot: file:/work/workspace/target/selenide-reports/1418221239308.0.png
Timeout: 10 s.
Caused by: NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//table[@id='overview']/tbody/tr[td[contains(@class, 'status')]/a='SEQLCOMP-94684']"}
    at com.codeborne.selenide.impl.AbstractSelenideElement.throwElementNotFound(AbstractSelenideElement.java:530)
    at com.codeborne.selenide.impl.WaitingSelenideElement.throwElementNotFound(WaitingSelenideElement.java:75)
    at com.codeborne.selenide.impl.AbstractSelenideElement.waitUntil(AbstractSelenideElement.java:522)
    at com.codeborne.selenide.impl.AbstractSelenideElement.waitUntil(AbstractSelenideElement.java:486)
    at com.codeborne.selenide.impl.AbstractSelenideElement.invoke(AbstractSelenideElement.java:167)
    at com.codeborne.selenide.impl.WaitingSelenideElement.invoke(WaitingSelenideElement.java:19)
    at com.sun.proxy.$Proxy5.waitUntil(Unknown Source)

I could of course catch ElementNotFound and retry, but I think the real problem is something different. So I have changed the code to

$(By.xpath("//table[@id='overview']/tbody/tr[td[contains(@class, 'status')]/a='SEQLCOMP-94684']")).waitUntil(not(hidden), 10000);

and now it works much better (if not perfect), but I think semantically that means something different: wait until element is hidden while I want to wait until the element is not shown.

Any ideas are welcomed.

-- 
With best regards,
Dmitry
xpath_selection.png

andrei....@gmail.com

unread,
Dec 12, 2014, 11:48:55 AM12/12/14
to Dmitry Katsubo, Mihhail Lapuškin
It seems that your xpath is not correct. 

To find element by text, you need to use "text()" function: /a[text(.)='SEQLCOMP-94684']

Sent from my HTC

--
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dmitry Katsubo

unread,
Dec 12, 2014, 12:21:43 PM12/12/14
to sele...@googlegroups.com
No, I don't think so.

First I have 75% of executions run OK. Second FirePath also finds this node. Third the specification reads:
  1. The string-value of an element node is the concatenation of the string-values of all text node descendants of the element node in document order.
  2. If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true.
  3. Example:
  • child::chapter[child::title='Introduction'] selects the chapter children of the context node that have one or more title children with string-value equal to Introduction

In my case the string-value of a-node is SEQLCOMP-94684.

Andrei Solntsev

unread,
Dec 12, 2014, 3:54:17 PM12/12/14
to Dmitry Katsubo, sele...@googlegroups.com
Ok, it seems you are right, the xpath is correct.

Try to observe this file: file:/work/workspace/target/selenide-reports/1418221239308.0.html

When Selenide does screenshot (file *.png), it also saves a html source of current page (file *.html). You can observe this file and find out if your element exists there).

Andrei Solntsev

Dmitry Katsubo

unread,
Dec 12, 2014, 6:48:55 PM12/12/14
to sele...@googlegroups.com
On 12/12/2014 21:53, Andrei Solntsev wrote:
Ok, it seems you are right, the xpath is correct.

Try to observe this file: file:/work/workspace/target/selenide-reports/1418221239308.0.html
Yes, I have opened this very file in FF, and I can see the node. And I can find it with xPath (see the screenshot attached to my 1st message, I have marked all bits there).

When Selenide does screenshot (file *.png), it also saves a html source of current page (file *.html). You can observe this file and find out if your element exists there).
... and I can see the node on the screenshot :)

The only two options that came to my mind:
  • FF on Windows behaves in this respect differently than FF on Linux (problem with xPath evaluation).
  • The node appears right after the timeout exceeds (10 seconds), but before the screenshot is taken. This is veeery unlikely.
Reply all
Reply to author
Forward
0 new messages