我有一个比较老的网站需要维护,支持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
的任何 如果您必须使用任何强制性
插件
,(对于所有 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
Add On
关于javascript - Selenium 启动时 IE11 失败并出现 "Netscape is not supported please used internet explorer"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47631849/