开发者

Selenium keypress esc not work in FireFox

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.


I reckon the XPath that you are using is putting into an infinite loop. I would remove the space that is between the //formand 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

  1. I don't think its valid xpath
  2. the // 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 loop

Remember that Selenium supports CSS selectors if you can do use them since it will make your IE tests run quicker

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜