使用以下代码尝试访问Google Chrome便携式浏览器。
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe");
driver=new ChromeDriver();
浏览器已打开,但立即关闭以下异常
例外:
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
任何人都可以帮我了解如何使用Selenium Webdriver访问Google Chrome便携式浏览器。
答案 0 :(得分:1)
下面的代码成功调用了Google Chrome便携式浏览器。
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe");
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\Browsers\\chromedriver.exe");
driver = new ChromeDriver(options);
答案 1 :(得分:0)
使用Chromedriver.exe在Chrome浏览器上运行测试用例。
String ChromeDriverPath= "path\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
WebDriver driver=new ChromeDriver();
Chromedriver exe可在
获得http://www.seleniumhq.org/download/
只需解压缩并提供Chromedriver.exe的路径
做一件事:
Public class processclass{
Process getBrowserProcess() {
Process p = null;
try {
p = Runtime.getRuntime()
.exec("C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe");
} catch (IOException e) {
e.printStackTrace();
}
return p;
}
}
另一个课程将包含您的测试用例。 所以创建一个上述类的对象,让我们说:
processclass Object = new processclass();
Object.getBrowserProcess();
然后运行你的驱动程序命令。
希望这能帮到你..