Java Selenium Chromedriver.exe 不存在 IllegalStateException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30688368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Selenium Chromedriver.exe Does not Exist IllegalStateException
提问by FaTal Cubez
Here is the error message I'm getting:
这是我收到的错误消息:
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Users\Scott\workspace\Twitch%20Bot%20v2\bin\chromedriver.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:122)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:117)
at org.openqa.selenium.chrome.ChromeDriverService.accessClassLoader loader = ClassLoader.getSystemClassLoader();
URL path = loader.getResource("chromedriver.exe");
System.setProperty("webdriver.chrome.driver", path.getPath());
(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:118)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:291)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:82)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
at com.fatalcubez.main.Bot.setup(Bot.java:41)
at com.fatalcubez.main.Bot.<init>(Bot.java:29)
at com.fatalcubez.main.BotGUI.<init>(BotGUI.java:17)
at com.fatalcubez.main.Main.main(Main.java:14)
And here is the code that I'm using:
这是我正在使用的代码:
System.setProperty("webdriver.chrome.driver",
"C:\Downloads\chromedriver.exe");
I've already check the directory for where it is searching for the chromedriver and it's there. I'm not sure what the problem is at this point. Any help would be great!
我已经检查了它在何处搜索 chromedriver 的目录,它就在那里。我不确定此时的问题是什么。任何帮助都会很棒!
EDIT: It was simply a problem with spacing in the folder name, but now I have another problem. When I try to launch chrome it says "An administrator has installed chrome on this computer...." What can I do?
编辑:这只是文件夹名称中的间距问题,但现在我有另一个问题。当我尝试启动 chrome 时,它说“管理员已在这台计算机上安装了 chrome....”我该怎么办?
采纳答案by Saritha G
You have to give your chromeDriver.exe file path instead of taking the path from the URL.
您必须提供 chromeDriver.exe 文件路径,而不是从 URL 获取路径。
example:
例子:
System.setProperty("webdriver.chrome.driver",
"/home/vin/Downloads/chromedriver");
回答by vinee
System.setProperty("webdriver.chrome.driver",
"/path where exe is present/chromedriver.exe");
Note- write the chromedriver without mentioning .exe (In Ubuntuand Mac)
注意 - 在不提及 .exe 的情况下编写 chromedriver(在Ubuntu和Mac 中)
回答by Archana
You can add the address of chrome driver exe in your code:
您可以在代码中添加chrome驱动程序exe的地址:
System.setProperty("webdriver.chrome.driver", "//Users//alinapanigrahi//bin//chromedriver");
WebDriver driver=new ChromeDriver();
or you can directly copy paste the exe of chrome driver in you workspace (C:\Users\Scott\workspace\Twitch Bot v2\bin\
)
或者您可以直接将chrome驱动程序的exe复制粘贴到您的工作区中(C:\Users\Scott\workspace\Twitch Bot v2\bin\
)
回答by Alina Behera
This worked for me:
这对我有用:
unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"686.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=58.0.3029.110)
But I got the unknown error:
但我收到了未知错误:
##代码##回答by PUNJRAJ SINGH RATHORE
Download the chromedriver:
下载 chromedriver:
From here unzip the folder and copy choromedriver.exe in c now set path like
从这里解压缩文件夹并在 c 中复制 choromedriver.exe 现在设置路径
回答by Aakshi Sharma
Locate your chrome driver file ( for windows) in the C drive under the user and the name of your device. Using any random folder and directing to that path will not work.
在用户和设备名称下的 C 驱动器中找到您的 chrome 驱动程序文件(适用于 Windows)。使用任何随机文件夹并指向该路径将不起作用。
System.setProperty("webdriver.chrome.driver","C:\\Users\\hp\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver","C:\\Users\\hp\\chromedriver.exe");
This works for me, and I think the reason is, the driver will search for the path that identifies your pc, like a default folder where they search for, as it will be more time consuming to search for random folders and can create errors when you have multiple copies of that chromedriver.exe
file like I had. Thanks, hope it works!
这对我有用,我认为原因是,驱动程序将搜索标识您的电脑的路径,例如他们搜索的默认文件夹,因为搜索随机文件夹会更耗时,并且可能会在以下情况下产生错误你有那个chromedriver.exe
文件的多个副本,就像我一样。谢谢,希望它有效!
回答by Ryan
Another thing to add, when using chromedriver with windows, you must include .exe in your systems properties call.
要添加的另一件事是,在 Windows 中使用 chromedriver 时,您必须在系统属性调用中包含 .exe。
valid call : System.setProperty("webdriver.chrome.driver", "res/chromedriver.exe");
有效电话: System.setProperty("webdriver.chrome.driver", "res/chromedriver.exe");
invalid call : System.setProperty("webdriver.chrome.driver", "res/chromedriver");
无效调用: System.setProperty("webdriver.chrome.driver", "res/chromedriver");
回答by kiran kumar
System.setProperty("webdriver.chrome.driver", "C:\Downloads\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", "C:\Downloads\chromedriver.exe");
Navigate to this path, right click and open the chromedriver.exe then a pop up is open Uncheck "the Always ask before open" . this works for me
导航到此路径,右键单击并打开 chromedriver.exe,然后打开一个弹出窗口,取消选中“打开前始终询问”。这对我有用