Mac用户Selenium求助:查找ChromeDriver路径及关闭浏览器弹窗
嘿,刚入坑Selenium的Mac用户看过来!这两个问题我帮你一步步解决:
问题1:搞定ChromeDriver路径配置
Mac上配置ChromeDriver路径其实很简单,我给你两种靠谱的方式:
- 用Homebrew安装(最省心):
打开终端敲这个命令:brew install chromedriver,安装完之后,ChromeDriver的默认路径分两种:- 英特尔芯片Mac:
/usr/local/bin/chromedriver - M系列芯片Mac:
/opt/homebrew/bin/chromedriver
直接把这个路径填到你的System.setProperty里就行。
- 英特尔芯片Mac:
- 手动下载配置:
- 先下载和你Chrome浏览器版本完全匹配的ChromeDriver(版本不匹配会报错!)
- 解压后把chromedriver文件放到你方便找的地方,比如桌面或者
/Applications文件夹 - 对应的路径比如桌面就是
"/Users/你的用户名/Desktop/chromedriver"(记得替换成你自己的Mac用户名)
配置代码示例:
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver"); // 换成你的实际路径
问题2:关闭浏览器通知弹窗
你代码里的参数格式错啦!--disable notifications要改成--disable-notifications(用短横线连接,不能有空格),这样才能正确禁用通知弹窗。如果之后还遇到其他弹出式窗口,也可以加个--disable-popup-blocking参数一起用。
完整修正后的代码
ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-notifications"); // 修正后的参数 System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver"); // 替换为你的ChromeDriver路径 WebDriver driver = new ChromeDriver(options); driver.get("https://www.sephora.com/");
内容的提问来源于stack exchange,提问作者freedamn
相关产品推荐
相关产品推荐

