线程函数中的Java代码:
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--user-data-dir="+config.chromeUserDir);
chromeOptions.addArguments("--profile-directory="+profile);
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.com");
Run Code Online (Sandbox Code Playgroud)
并使用以下代码创建对象并在线程中启动
Driver d1 = new Driver(profile);
d1.start();
Driver d2 = new Driver(profile1);
d1.start();
Run Code Online (Sandbox Code Playgroud)
已经创建了两个不同的配置文件,代码在单线程下运行良好,但在多线程下它不会在两个单独的窗口中打开谷歌网站。它说,
Starting ChromeDriver 2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac) on port 25692
Only local connections are allowed.
Starting ChromeDriver 2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac) on port 25954
Only local connections are allowed.
Oct 14, 2018 2:10:46 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Oct 14, 2018 2:10:46 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Created new …
Run Code Online (Sandbox Code Playgroud)