Selenium with Python- 消息:'operadriver' 可执行文件需要在 PATH 中

Selenium with Python- Message: 'operadriver' executable needs to be in PATH

检查网站是否使用带有 python 的 selenium 在 Opera 中加载,使用以下代码:

def test_opera_compatability(self):
    driver = webdriver.Opera("functional_tests/operadriver")
    driver.get("https://www.google.com/")
    driver.quit()

它returns出现以下错误:

Message: 'operadriver' executable needs to be in PATH.

chrome 的类似代码按预期工作,如下所示:

def test_chrome_compatability(self):
    driver = webdriver.Chrome('functional_tests/chromedriver')
    driver.get("https://www.google.com/")
    driver.quit()

可以使用Keyexecutable_path传递绝对路径 operadriver 二进制文件如下:

def test_opera_compatability(self):
    driver = webdriver.Opera(executable_path='/path/to/functional_tests/operadriver')
    driver.get("https://www.google.com/")
    driver.quit()