包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.
答案 0 :(得分:0)
以下是您的问题的答案:
您需要解决以下几个问题:
System.setProperty
/
(正斜杠),要么你必须逃避反斜杠\\
您看到log4j:WARN Please initialize the log4j system properly.
的错误日志是因为您已配置log4j
以生成其他日志并将其写入其中一个类文件的文件中。该配置仍然保留在您的项目级别,但您尚未处理此类文件中的log4j
设置。因此,您会看到log4j:WARN
,但它们是无害的,您无需担心它们。
这是您自己的工作代码,其中包含一些简单的调整:
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");
如果这回答你的问题,请告诉我。