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 (“Selenium, SikuliX and Facebook posting“).

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.

Leave a Reply

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