尝试使用以下代码使用webdrivermanager初始化chrome浏览器
WebDriverManager.chromedriver().proxy(proxyName).setup();
driver = new ChromeDriver();
driver.get(prop.getProperty("url"));
通过使用以下代码设置系统属性,尝试使用chrome驱动程序初始化chrome浏览器
System.setProperty("webdriver.chrome.driver", "C:\\Users\\geckodriver\\chromedriver_win32\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--no-sandbox"); // Bypass OS security model
options.addArguments("--verbose");
options.addArguments("--whitelisted-ips=''");
options.addArguments("--proxy-server=proxyName);
面对错误
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
[RemoteTestNG] detected TestNG version 6.14.3
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809@{#864}) on port 35481 Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
Ordinal0 [0x009B7C93+1473683]
Ordinal0 [0x0093ADB1+961969]
Ordinal0 [0x008C42E3+475875]
Ordinal0 [0x0085EA04+59908]
Ordinal0 [0x0085BBD7+48087]
Ordinal0 [0x00879149+168265]
Ordinal0 [0x00878D1D+167197]
Ordinal0 [0x0087742B+160811]
Ordinal0 [0x00860AE6+68326]
Ordinal0 [0x00861BF0+72688]
Ordinal0 [0x00861B89+72585]
Ordinal0 [0x00954B77+1067895]
GetHandleVerifier [0x00A56875+506677]
GetHandleVerifier [0x00A56610+506064]
GetHandleVerifier [0x00A5D1B8+533624]
GetHandleVerifier [0x00A5704A+508682]
Ordinal0 [0x0094C266+1032806]
Ordinal0 [0x0094C0DF+1032415]
Ordinal0 [0x00956A8B+1075851]
Ordinal0 [0x00956BF3+1076211]
Ordinal0 [0x00955BA5+1072037]
答案 0 :(得分:0)
在调用webdriver对象时尝试以下标志
System.setProperty("webdriver.chrome.driver", "C:\\user\\driver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("--no-sandbox");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-gpu");
options.addArguments("--disable-dev-shm-usage");
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");