Automating Opera browser with Selenium WebDriver and Python

The right way to automate a web application is, certainly, to understand how this application works, by using burp (see “Burp Suite Free Edition and NTLM authentication in applications“) for example, retrieve all necessary requests and learn how to use them.

However, this is sometimes so difficult and confusing, especially when the site owners are actively fighting with automation attempts. In this case, you may want to automate somehow the work on the highest level, with the graphical elements of the site. You can view them as some pictures, as SikuliX does (“SikuliX: the last chance for automation“, or as some elements of code, as Selenium IDE does.

But it would much better to control the browser itself from the Python scripts. And this can be done with Selenium WebDriver.

Selenium WebDriver, Python and Opera browser

Guys from Guru99 have wrote me a letter about their free course about Selenium.

This course looks pretty good. In the first part you can find a detailed description of Selenium components and the project history. After reading this, I finally decided that the Selenium WebDriver suited me best. Examples of WebDriver usage are written in Java, and I wanted to use Python. But since the calls are the same, lessons of this course are still more than useful.

And despite the fact that Selenium is usually used with Firefox, I tried to use it with Chromium-based Opera. This browser is very popular in Russia because of some unique features. 😉

Installing Selenium:

$ pip install selenium
Collecting selenium
  Downloading selenium-3.5.0-py2.py3-none-any.whl (921kB)
    100% |████████████████████████████████| 921kB 665kB/s 
Installing collected packages: selenium
Successfully installed selenium-3.5.0

Selecting and downloading from

Putting the file in operadriver_linux64/operadriver to my python project folder:

$ ls operadriver_linux64/
operadriver sha-512_sum

Launching my opera-developer with the port number:

$ opera-developer --remote-debugging-port=1212

And here is the code for controlling Opera browser:

from selenium import webdriver
from import service

from bs4 import BeautifulSoup

webdriver_service = service.Service('operadriver_linux64/operadriver')

capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}

driver = webdriver.Remote(webdriver_service.service_url, capabilities)


input_txt = driver.find_element_by_name('q')

soup = BeautifulSoup(driver.page_source, 'html.parser')

for site in soup.find_all('h3'):
    for child in site.children:


The driver took an active tab of Opera browser, opened in it, found text field on the page, typed “operadriver” there and made a search request.

Opera WebDriver Google search

Then I’ve got full page code and was able to find the search results using Beautiful Soup (pip install beautifulsoup4).


operadriver - Google Search
GitHub - operasoftware/operachromiumdriver: OperaDriver for ...
Releases · operasoftware/operachromiumdriver · GitHub
OperaDriver should look for the Opera executable on the PATH by ...
operadriver - npm
OperaDriver Released | Official Selenium Blog
Selenium WebDriver and Opera Driver - Stack Overflow
Chocolatey Gallery | Selenium Opera Driver 2.29
Dev.Opera — OperaDriver Is Now a Part of Selenium and Has ...
Maven Repository: com.opera » operadriver » 0.7.3
Searches related to operadriver

As you can see, it works. You can deal with the WebDriver and automate some specific tasks Starting point for documentation:

However, some problems were found:

1. Sometimes it become impossible to restart the script, if the browser tab was left opened:

selenium.common.exceptions.WebDriverException: Message: session not created exception
from unknown error: failed to close UI debuggers

You need to close the tab manually, and then everything works.

It would be possible for the script to close the tabs automatically, but you can work with the browser GUI elements only by using keystroke emulation and here is the problem 2.

2. Pressing special keys, including Keys.CONTROL doesn’t work. I tried this ways:

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')

But ActionChains mechanism itself works. I can click on Google logo for example:


I’ve been googling solution for a long time, but  still can’t get it work.

3 thoughts on “Automating Opera browser with Selenium WebDriver and Python

  1. Pingback: New Nessus 7 Professional and the end of cost-effective Vulnerability Management (as we knew it) | Alexander V. Leonov

  2. Pingback: Splunk Discovery Day Moscow 2018 | Alexander V. Leonov

  3. Pierre Marsaa

    Hi !
    i am a beginner in python and i tryed your code but it doesn’t work and idk why
    it seems like the line : driver = webdriver.Remote(webdriver_service.service_url, capabilities)
    don’t work, butit’s just like, nothing happend, it’s like i’m in an infinite loop when this line is called

    i’m on windows so i made some changes (like : webdriver_service = service.Service(‘operadriver_win64/operadriver’) or the “localhost:1212” into “localhost:9515”)
    but i think it doesn’t work because of this two lines in your explanation :

    Launching my opera-developer with the port number:
    $ opera-developer –remote-debugging-port=1212

    i don’t know how to do that with windows, so, if you can help me with that, you’ll be very cool !


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.