我是Mac OSX的新手。从git下载了我的Robotframework(Selenium& Java)项目,并尝试在本地执行代码,我收到了以下错误。
套件设置失败: IllegalStateException:驱动程序不可执行:/ Users / roja / Documents / GitHub / testautomation / chromedrivers / chromedriver_osx
为了纠正这个问题,我按照下面的说法进行了操作,但它没有用。
- 将selenium-java和独立版本从2.53.1升级到3.4.0。
- 指定给Users / roja / automation
的驱动程序路径- Chromedriver从2.31升级到2.33
- 即使在上述例外中指定的路径中,相同的驱动程序版本也会更新。
另外我不确定为什么路径默认为/Users/roja/Documents/GitHub/testautomation/chromedrivers/chromedriver_osx
。
我的git项目保存在usr / local / git / testautomation路径中,chromedriver也保存在同一个路径中。请澄清并为我提供解决方案。
下面为启动浏览器而编写的代码
public void LaunchBrowser() throws InterruptedException {
System.setProperty("Webdriver.chrome.driver", "/Users/roja/Automation/chromedriver_osx");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
答案 0 :(得分:5)
错误IllegalStateException: The driver is not executable: /Users/roja/Documents/GitHub/testautomation/chromedrivers/chromedriver_osx
说明了一切。您必须按如下方式进行4次更改:
将Webdriver.chrome.driver
更改为:
webdriver.chrome.driver
更改/Users/roja/Automation/chromedriver_osx
,因为我们需要将webdriver binary
的名称包括 chromedriver
作为 value
< / strong>:
/Users/roja/Automation/chromedriver_osx/chromedriver
将driver = new ChromeDriver();
更改为:
WebDriver driver = new ChromeDriver();
删除不需要的throws InterruptedException
以保持代码简洁明了。
答案 1 :(得分:2)
仅供参考,我必须执行varunrao321建议的解决方案:导航至包含chromedriver的文件夹并运行chmod +x chromedriver
答案 2 :(得分:1)
另一种对我有用的解决方案。 导航到包含chromedriver的文件夹并运行 “chmod + x chromedriver”
答案 3 :(得分:1)
我尝试给予chromedriver完全许可,并且效果很好。
chmod +x chromedriver
或
chmod 777 chromedriver
答案 4 :(得分:0)
@debanjan已经向你解释了很好的解释,我只是给你正确的代码:
public void LaunchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "/Users/roja/Automation/chromedriver_osx/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
}
答案 5 :(得分:0)
这可能是由于权限访问所致。使用http://chromedriver.chromium.org/downloads下载chrome驱动程序,然后提供路径。
示例:
System.setProperty("webdriver.chrome.driver","/Users/xyz/Downloads/chromedriver");
答案 6 :(得分:0)
我解决此问题的方法是通过右键单击>导入导入chromedriver,而不是将其拖动到文件夹中。
我不知道为什么,但是可以。
答案 7 :(得分:0)
对我来说,这是最后一个与我的macOS mojave上安装的chrome版本不兼容的驱动程序。我被迫安装了最新版本的google chrome,然后就可以了。
答案 8 :(得分:0)
您可以通过brew安装chromedriver
brew cask install chromedriver
然后,如DebanjanB所说,替换您的
System.setProperty(“ Webdriver.chrome.driver”,“ / Users / roja / Automation / chromedriver_osx”);
与
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
对我有用。
答案 9 :(得分:0)
也为我工作:
第1步:打开终端
步骤2:导航到包含chromedriver
的路径文件夹
步骤3:执行chmod +x chromedriver
答案 10 :(得分:0)
另一个解决方案:
访问:https://sites.google.com/a/chromium.org/chromedriver/downloads enter image description here
在“当前版本”部分中,单击系统中已更新的Chrome驱动程序链接。
它将自动重定向到“ https://chromedriver.storage.googleapis.com/index.html?path=“ enter image description here
单击mac链接并解压缩该文件夹。
现在将chromedriver.exe文件粘贴到您的项目中。
并提供以下提到的代码-
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SetChromeDriver {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
driver.quit();
}
}
答案 11 :(得分:0)
在存在chromedriver
的文件夹中运行以下命令:chmod +x chromedriver