javascript - Selenium 启动时 IE11 失败并出现 "Netscape is not supported please used internet explorer"错误

标签 javascript selenium internet-explorer-11

我有一个比较老的网站需要维护,支持IE8及以上。 现在我计划使用 Selenium WebDriver(版本 3.7.1)在网站上进行一些测试自动化。除了一些使用 document.getElementById() 的页面外,几乎所有内容都运行良好。关键是,这些页面利用了 IE11 的“特性”,即当没有元素与指定 ID 匹配时,它会返回具有该 ID 的元素作为名称(如 this thread 中所示)。
当浏览器(IE11)由 selenium 启动时,它无法调用该代码(返回 NULL,导致错误)。
进一步调查,我发现,当手动启动时,调用 navigator.appName 返回“Microsoft Internet Explorer”,而在其他情况下返回“Netscape”。
这种差异意味着什么,这是我的问题的根本原因。最重要的是,如何解决这个问题?

我正在使用此源代码启动页面:

DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
WebDriver driver = new InternetExplorerDriver(
                    new InternetExplorerOptions(ieCapabilities));
wait = new WebDriverWait(driver, 30);
driver.get(url);

最佳答案

正如您提到的,调用 navigator.appName 返回“Microsoft Internet Explorer”,而在另一种情况下返回“Netscape” 是一种罕见但普遍存在的情况。完整的错误如下:

"Netscape is not supported please used internet explorer "

解决方案:

要解决这个问题,您必须考虑以下几点:

  • Internet Explorer Driver 在真实浏览器中运行并支持 Javascript。
  • 尽量避免使用 Internet Explorer
  • 的任何Add On
  • 如果您必须使用任何强制性插件,(对于所有 IE9、IE10、IE11 和 Windows 8 用户)

    1. Open the desired website in Internet Explorer
    2. Go to "Compatibility View settings" (image shown below)
    3. In a dialog box add your website in the list.
    e.g. if you are trying to use "ssconline.nic.in" , then add "nic.in" in the list 
    

CompatibilityViewSettings_IE

关于javascript - Selenium 启动时 IE11 失败并出现 "Netscape is not supported please used internet explorer"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47631849/

相关文章:

css - 使 flexbox 在 IE11 中继承适当的宽度

javascript - 如何减少这种比较循环

javascript - 自动将 CSV 文件读入 Javascript 代码

Selenium 最佳实践 : One Long Test or Several Successively Long Tests?

python - 让 Selenium Webdriver 跨 Celery 任务

css - 在 Quirks 模式下运行的 IE11 中使用 css 制作灰度图像

javascript - swfObject 嵌入对象在 ie11 中不起作用

javascript - 媒体按钮/Javascript

javascript原型(prototype)构造函数混淆

java - 将 Selenium 与 HP ALM 集成