【问题标题】:Open browser on Mac with python在 Mac 上用 python 打开浏览器
【发布时间】:2021-11-22 18:56:26
【问题描述】:

如何描述MAC上chrome的路径? 我使用了这段代码:

import time
from selenium import webdriver
driver = webdriver.Chrome('../chromedriver')  # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
time.sleep(5)  # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5)  # Let the user actually see something!
driver.quit()```

I got error: **DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome('../chromedriver')  # Optional argument, if not specified will search path.**

【问题讨论】:

标签: python google-chrome


【解决方案1】:

“错误”只是一个警告;您的代码应该可以使用它。尽管如此,修复弃用错误还是不错的,因为代码可能很快就会停止工作。这不应该发出错误:

from selenium import webdriver

# modify if different
chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'

chrome_service = webdriver.chrome.service.Service(chrome_path)
driver = webdriver.Chrome(service=chrome_service)

当然,你也可以下载chromedriver。如果您不想担心您的 Chrome 或chromedriver 在哪里,您可以使用webdriver_manager,它会在必要时自动为您下载驱动程序,并为您提供路径:

from webdriver_manager.chrome import ChromeDriverManager

chrome_path = ChromeDriverManager().install()

【讨论】:

    猜你喜欢
    • 2013-11-07
    • 2019-04-12
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 2014-04-22
    • 2021-03-26
    • 2012-04-17
    • 1970-01-01
    相关资源
    最近更新 更多