Reputation: 385
I wrote this code for my unit tests in c# with selenium to test my web application. In particular I'm testing that the window for the tooltip is properly displayed and after esc key press it disappears:
private const string XPathToolTipStyle = "//form[@action='search.aspx'] //div[@id='searchToolTip']/@style";
private bool IsToolTipOpen()
{
var tempToolTip = selenium.GetAttribute(XPathToolTipStyle);
return !(tempToolTip).ToLower().Contains("display: none;");
}
[Test]
public void PressEscAndCloseClosingKeys()
{
writeSomethingInTheInputBox();
Assert.That(IsToolTipOpen());
selenium.KeyPressNative("27"); //press esc
Assert.That(!IsToolTipOpen());
}
the problem is that in Internet Explorer it works correctly, but in Firefox it goes in infinite loop in IsToolTipOpen() whitout exit and return a value. I've just tried to use keyDown, KeyPress etc... but it dosen't work. thank you.
Upvotes: 0
Views: 2665
Reputation: 22438
I reckon the XPath that you are using is putting into an infinite loop. I would remove the space that is between the //form
and the //div
and one of the slashes in front of the div
private const string XPathToolTipStyle = "//form[@action='search.aspx']/div[@id='searchToolTip']/@style";
The reason why I suggest changing it is
//
will tell the Xpath to search the entire document and since you are doing it tell it to search for the form and then start again to search for the div so its then going into the wierd infinite loopRemember that Selenium supports CSS selectors if you can do use them since it will make your IE tests run quicker
Upvotes: 1