selenium接手手动打开的谷歌浏览器

java selenium 启动谷歌

//设置谷歌驱动位置
System.setProperty("webdriver.chrome.driver", "C:\\robot\\chromedriver.exe");
//谷歌浏览器启动端口
int port = 8088;
//打开浏览器地址
String url = "https://www.baidu.com/";
//设置谷歌启动参数 
//1 双击打开浏览器 chrome://version/
//2 复制 命令行 
String str = "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --register-pepper-plugins=\"C:\\Program Files (x86)\\KGChromePlugin\\KGChromePlugin_32.dll;application/kg-plugin\" --test-type --no-sandbox --disable-infobars --disable-hang-monitor --flag-switches-begin --flag-switches-end --origin-trial-disabled-features=WebGPU --remote-debugging-port=" + port + " --user-data-dir=\"C:\\robot\\selenium\" " + url;
//设置谷歌浏览器目录
System.setProperty("webdriver.chrome.bin", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
//执行启动谷歌
Runtime.getRuntime().exec(str);
//创建 Robot 实例
robot = new Robot();
//执行完一个事件后再执行下一个
robot.setAutoWaitForIdle(true);
ChromeOptions chromeOptions = new ChromeOptions();
//指定启动端口 与打开的浏览器端口一致
chromeOptions.setExperimentalOption("debuggerAddress", "localhost:" + port);
driver = new ChromeDriver(chromeOptions);
//浏览器最大化
driver.manage().window().maximize();
//设置全局读取超时时间
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值