gpt4 book ai didi

java - Eclipse 无法找到 chrome 库

转载 作者:行者123 更新时间:2023-12-01 19:31:23 24 4
gpt4 key购买 nike

我对 Selenium 世界还很陌生。我一直被这个打开基本 Facebook 页面的代码所困扰,它一直抛出一个错误:

Starting ChromeDriver 78.0.3904.105 (60e2d8774a8151efa6a00b1f358371b1e0e07ee2-refs/branch-heads/3904@{#877}) on port 8852 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48' System info: host: 'ATLMD2226268', ip: '10.7.0.108', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'

我使用的代码是:

package NewPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class MyClass {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\vaaggarw\\Downloads\\chromedriver_win32\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files (x86)\\Google Chrome (Local)\\chrome.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://www.facebook.com";
String tagName = "";

driver.get(baseUrl);
tagName = driver.findElement(By.id("email")).getTagName();
System.out.println(tagName);
driver.close();
System.exit(0);
}
}

最佳答案

  1. 确保您的项目中没有丢失所有 Selenium jar 。如果没有,无论如何删除它们并从新下载添加新的 jar
  2. 清理您的项目
  3. 按照 pcalkins 的建议,正确使用 chrome 选项

关于java - Eclipse 无法找到 chrome 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59257400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com