Selenium WebDriver与InternetExplorerDriver在兼容模式下单击标签

本文关键字:模式 单击 标签 WebDriver InternetExplorerDriver Selenium | 更新日期: 2023-09-27 18:22:02

在intranet或启用"兼容性视图"的站点上调试(即IE不集中)时,是否有人成功单击标签?我已经尝试了我能想到的EnableNativeEvents/RequireWindowFocus/EnablePersistentHover的每一种组合(RequireWindowFocus只是挂起浏览器),除了发送一个js片段来点击什么都不起作用。

这里,Process.Start模拟失去焦点,例如,当碰到断点时。

Windows 7 x64,IE 10 x86,WebDriver 2.33.0.0,IEDriverServer Win32 2.33.0

[Test]
public void CompatibilityViewLabel()
{
    var options = new InternetExplorerOptions
    {
        EnableNativeEvents = false,
        //RequireWindowFocus = true,
        //EnablePersistentHover = true,                
    };
    var driver = new InternetExplorerDriver(options);
    driver.Navigate().GoToUrl("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_label");
    var filter = (byte[])Registry.CurrentUser.OpenSubKey(@"Software'Microsoft'Internet Explorer'BrowserEmulation'ClearableListData").GetValue("UserFilter");
    if (filter == null || !Encoding.Unicode.GetString(filter).Contains("w3schools.com"))
        Assert.Fail("Click Compatibility View icon and retest.");
    driver.SwitchTo().Frame("iframeResult");
    var input = driver.FindElement(By.Id("male"));
    var label = driver.FindElement(By.CssSelector("label[for='male']"));
    Process.Start("cmd");
    label.Click();
    //driver.ExecuteScript("arguments[0].click()", label);
    Assert.IsTrue(input.Selected);
}

Selenium WebDriver与InternetExplorerDriver在兼容模式下单击标签

该页面格式不正确,它有两个body元素,而您要查找的元素在第二个body中。请使用其他页面进行尝试。

您应该尝试放入:

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5));
wait.Until(drv => drv.FindElement(By.Id("male"));

在label.click()之前;

在https://code.google.com/p/selenium/issues/detail?id=5977和示例页,位于http://jsbin.com/ijaqog