Controlling Opera with Selenium

This is a quick guide on how to use Selenium to control Opera, e.g. from Python.

Requirements

Usage

Selenium already includes an Opera driver, so you can just start using it with any programming language.

Python (2.x)

First, install the selenium package. The version should match the Selenium server version. For example:

pip install selenium==2.41.0

You can then use it like this:

import selenium.webdriver

Caps = selenium.webdriver.DesiredCapabilities.OPERA.copy()
Caps["opera.binary"] = operaPath
Driver = selenium.webdriver.Opera(
  executable_path=seleniumServerPath,
  desired_capabilities=Caps
)

Driver.get("https://www.opera.com/")

for i in Driver.find_elements_by_tag_name("a"):
  URL = i.get_attribute("href")
  if URL:
    print(URL)

Driver.close()

Replace operaPath with the full path and name of the Opera executable (this might only be necessary if your installation is a "portable" one) and seleniumServerPath with the full path and name of the Selenium standalone server JAR file.

Make sure that java.exe is accessible through your PATH variable and run the script. You should see an Opera window open, navigate to the specified page, and the URLs of all linked pages printed to the console.

See also


First published on .
Last updated on .

Table of contents

Contact me