2017-05-19 57 views
-2

package ICICI;獲取異常log4j:WARN請正確初始化log4j系統

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. 
+0

您遇到的異常與實際錯誤沒有關係。如果仔細觀察,您應該嘗試解決的錯誤是「線程中的異常」主「org.openqa.selenium.remote.UnreachableBrowserException:與遠程瀏覽器通信時出錯。它可能已經過世。# –

+0

@Amreeta您能否使用您正在使用的Selenium,ChromeDriver和Google Chrome版本更新我們 – DebanjanB

回答

0

這裏是回答你的問題:

你需要如下解決幾件事情:

  1. 要使用Selenium 3.4.0,您需要從下載最新的chromedriver v2.並將您的谷歌瀏覽器升級到58.x。在您的計算機上保存該驅動器,並提供絕對路徑,同時提及System.setProperty
  2. 雖然提到了色塊驅動程序的絕對路徑,您可以提供單個/(正斜槓),或者您必須逃避反斜槓\\
  3. 您看到log4j:WARN Please initialize the log4j system properly.的錯誤日誌是因爲您已配置log4j來生成其他日誌並寫入其中一個Class文件的文件。該配置仍然保留在您的項目級別,但您尚未處理此Class文件中的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"); 
    

讓我知道如果這個回答你的問題。

+0

非常感謝。這有助於。 :) 萬分感激。 – Amreeta

相關問題