获取异常log4j:WARN请正确初始化log4j系统

时间:2017-05-19 14:25:02

标签: selenium log4j

包ICICI;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class ICICI_CareerHomePage {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Starting Execution");
        System.setProperty("webdriver.chrome.driver", "C://Users//Public//MessageCentre//InputFiles//chromedriver.exe");


        DesiredCapabilities capabilities = DesiredCapabilities.chrome();

        ChromeOptions options = new ChromeOptions();

        String useragent= "Mozilla/45.4.0 (Windows NT 6.1\\; WOW64) 
        AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 WFBTesting";

        options.addArguments("--user-agent=" +useragent);

        options.addArguments("--test-type");

        options.addArguments("--allow-running-insecure-content");

        options.addArguments("disable-infobars");

        capabilities.setCapability(ChromeOptions.CAPABILITY, options);

        //driver.additional.capabilities={"chromeOptions":{"args":["--user-agent=Mozilla/5.0 (Windows NT 6.1\\; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36 WFBTesting"]}};

        WebDriver driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://www.google.com/");
        System.out.println("ICICI Home Page Opened");
    }

}

我已经编写了上面的代码,但它抛出了异常:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.

1 个答案:

答案 0 :(得分:0)

以下是您的问题的答案:

您需要解决以下几个问题:

  1. 要使用Selenium 3.4.0,您需要从here下载最新的chromedriver v2.29并将您的Google Chrome升级到58.x。将chromedriver保存在您的机器中并提供绝对路径提到System.setProperty
  2. 虽然提到了chromedriver的绝对路径,但要么提供单/(正斜杠),要么你必须逃避反斜杠\\
  3. 您看到log4j:WARN Please initialize the log4j system properly.的错误日志是因为您已配置log4j以生成其他日志并将其写入其中一个类文件的文件中。该配置仍然保留在您的项目级别,但您尚未处理此类文件中的log4j设置。因此,您会看到log4j:WARN,但它们是无害的,您无需担心它们。

  4. 这是您自己的工作代码,其中包含一些简单的调整:

        System.out.println("Starting Execution");
        System.setProperty("webdriver.chrome.driver","C:\\Utility\\BrowserDrivers\\chromedriver.exe");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        String useragent= "Mozilla/45.4.0 (Windows NT 6.1\\; WOW64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 WFBTesting";
        options.addArguments("--user-agent=" +useragent);
        options.addArguments("--test-type");
        options.addArguments("--allow-running-insecure-content");
        options.addArguments("disable-infobars");
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        WebDriver driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://www.google.com/");
        System.out.println("ICICI Home Page Opened");
    
  5. 如果这回答你的问题,请告诉我。