java+selenium接管已打开的浏览器
//先设置chrome的环境变量,打开chrome的安装路径,添加路径到环境变量path上,然后打开下面的命令行,我打开的时候遇到了打开的浏览器一直崩溃,
//详情解决查看https://blog.csdn.net/weixin_42507239/article/details/106630121
public static void main(String[] args) throws InterruptedException {
// chrome.exe --remote-debugging-port="9527" --user-data-dir="D:\selenium\AutomationProfile"
System.setProperty("webdriver.chrome.driver","src/main/resources/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9527");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.baidu.com");
String title = driver.getTitle();
System.out.printf(title);
Thread.sleep(3000L);
driver.close();
}
本文来自博客园,作者:墨鱼鱼鱼,转载请注明原文链接:https://www.cnblogs.com/zengjiawei/articles/15623153.html
浙公网安备 33010602011771号