我的博客

MacOS上使用Selenium控制Safari

目录

苹果官方文档:

https://developer.apple.com/documentation/webkit/about_webdriver_for_safari

https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari

  1. 首先要确认 safaridriver 已经安装,路径在 /usr/bin/safaridriver

  2. 然后修改 Safari 配置允许自动控制

    image.png

    先在配置中显示 Develop 菜单,然后到 Develop 菜单中开启运行远程自动控制

    image.png

  3. 安装 selenium

    pip3 install selenium

  4. 使用 selenium 启动浏览器

    1
    2
    3
    4
    from selenium import webdriver

    driver = webdriver.Safari()
    driver.get('https://codeplot.top/')

评论无需登录,可以匿名,欢迎评论!