【问题标题】:Mac OS X 10.12 Sierra selenium PythonMac OS X 10.12 Sierra 硒 Python
【发布时间】:2016-11-02 17:26:46
【问题描述】:

我正在尝试使用安装在 Macbook Air 上的 Python 2.7 运行 Selenium Python 脚本并获得 ERR:

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("test-type")
driver = webdriver.Chrome(chrome_options=chrome_options)
**driver.get("https://www.google.com/");**
driver.quit()

还安装了 Python 3.5,但从 python3 运行 ERR 无法找到模块: ImportError: 没有名为“selenium”的模块

非常感谢任何帮助

【问题讨论】:

  • pip3 install selenium?
  • 试过了:>>> driver.get("google.com/"); Traceback(最近一次调用最后):文件“”,第 1 行,在 文件“/Library /Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py",第 248 行,在 get self.execute(Command.GET, {'url': url})
  • 也尝试过使用python3:
  • >>> driver.get("google.com/"); Traceback(最近一次调用最后):文件“”,第 1 行,在 文件“/Library/Frameworks/ Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py”,第 248 行,在 get self.execute(Command.GET, {'url': url})

标签: python macos selenium


【解决方案1】:

我终于回到了这一点,现在我可以在运行 macOS Sierra (10.12.1) 的 MacBook Air 上同时使用 FireFox 和 Chrome 以及 Selenium 3。我使用了 FF 50.1.0、Selenium 3 和 Python 2.7.10 或 Python 3.5.2

# -*- coding: utf-8 -*-
#/usr/local/bin/geckodriver (in PATH)

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/Volumes/Untitled/Applications/Firefox.app/Contents/MacOS/firefox'
browser = webdriver.Firefox(capabilities=firefox_capabilities)
browser.get("https://www.google.com")
browser.quit()

【讨论】:

    猜你喜欢
    • 2017-03-06
    • 1970-01-01
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    相关资源
    最近更新 更多