如何在 Mac 上使用 chrome、selenium、chromedriver 启用远程调试

时间:2021-07-22 22:20:14

标签: java selenium selenium-chromedriver port

我想重新使用在我的 Mac 上运行的现有 Chrome 浏览器。

从互联网上看,我需要用参数打开 chrome,然后运行 ​​java 代码并设置端口号。不幸的是,我仍然遇到错误。

从终端在端口 9222 上打开 chrome:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port-9222 --user-data-dir="~ChromeProfile"

程序中用于连接到 chrome 的 Java 代码:

    WebDriver dr = null;
    location = "/Users/xx/Downloads/chromedriver";
    System.setProperty("webdriver.chrome.driver", location);
    ChromeOptions options = new ChromeOptions();
    //options.addArguments("--remote-debugging-port=9222");
    //options.setExperimentalOption("--remote-debugging-port", "localhost:9222");
    options.setExperimentalOption("debuggerAddress", "localhost:9222");
    dr = new ChromeDriver(options);
    dr.navigate().to(myLink);

Netbeans 不断打开一个随机端口而不是 9222;

Starting ChromeDriver 9X.X.XXXX.XX (8c61b7e2989f2990d42f859cac71319137787cce-refs/branch-heads/4515@{#306}) on port 4188
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

我做错了什么?

0 个答案:

没有答案
相关问题