我用 selenium 在 c# 中为我的单元测试编写了这段代码来测试我的 web 应用程序。特别是我正在测试工具提示的窗口是否正确显示,并且在按下 esc 键后它会消失:
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());
}
问题是在 Internet Explorer 中它可以正常工作,但在 Firefox 中,它在 IsToolTipOpen() 中进入无限循环,但退出并返回一个值。我刚刚尝试使用 keyDown、KeyPress 等……但它不起作用。谢谢你。