错误"警告没有找到记录器的追加器"使用Java在Selenium中打开IE时

时间:2017-11-27 06:46:01

标签: selenium internet-explorer

我正试图通过selenium打开IE 计划:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class testnew
{

    public static void main(String...args)
    {
        System.out.println("hi");
        WebDriver driver=new InternetExplorerDriver();
        driver.get("http://www.google.com");
        //driver.close();
    }
}

错误:

  

输出显示如下,之后是错误。你能   请告诉我这是什么错误。

 Started InternetExplorerDriver server (32-bit)
    2.44.0.0
    Listening on port 27138
    log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.17 seconds
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: host: 'TCCD3140', ip: '172.17.22.99', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_40'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:162)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:227)
    at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:182)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:174)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:146)
    at testnew.main(testnew.java:11)

系统:

64位

1 个答案:

答案 0 :(得分:0)

您谈到的错误:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).

这是WARNING,无论如何都不会造成伤害。您之所以看到它,是因为您已使用同一项目中的程序配置了Log4j Logger Module类。由于此特定脚本/程序未配置Log4j Logger Module,因此您会看到错误。

但你的主要错误是:

SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)

要摆脱这种情况,你必须这样做:

  • IEDriverServer 可执行文件必须为downloaded并放入您的系统中。
  • 在Windows Vista或Windows 7上的IE 7或更高版本中,您必须将每个区域的 Protected Mode 设置设置为相同的值。值可以是 ON OFF ,只要每个区域都相同即可。要设置 Protected Mode settings ,请从 Internet Options... 中选择 Tools menu ,然后点击 Security tab 即可。对于每个区域,选项卡底部都会显示一个标记为 "Enable Protected Mode" 的复选框。
  • 此外,对于IE 10及更高版本,必须禁用 Enhanced Protected Mode 。此选项位于 Advanced Tab 对话框的 Internet Options 中。
  • Browser Zoom Level 必须设置为 100% ,以便将原生鼠标事件设置为正确的坐标。
  • 对于Windows 10,您还需要在 Change the size of text, apps, and other items 中将 100% 设置为 Display settings
  • 仅对于IE 11,您需要在目标计算机上设置 Registry Entry ,以便驱动程序可以维护与其创建的Internet Explorer实例的连接。对于32位Windows安装,您必须在注册表编辑器中检查的密钥是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE 。对于64位Windows安装,密钥为 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE 。请注意, FEATURE_BFCACHE subkey 可能存在也可能不存在,如果不存在,则应创建 DWORD 。重要提示:在此密钥中,创建名为 iexplore.exe 0 值,其值为 setProperty("")
  • 您自己的代码经过简单的调整(添加System.setProperty("webdriver.ie.driver", "C:\\your_directory\\IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(); driver.get("https://www.google.co.in"); System.out.println("Google Home Page Opened"); driver.quit(); System.out.println("Driver Closed"); 行)将如下所示:

    IEDriverServer.exe
  • 当您提供 / 的绝对路径时,请使用单个前斜杠\\或使用转义后斜杠Instance is not managed Waiting for device mounted to come online : /dev/xvdf Volume /dev/sdf has failed to attach - aborting Warning: ec2-startup did not complete successfully Check the error logs for details Starting MarkLogic: [FAILED] 。< / p>