Skip to content

Instantly share code, notes, and snippets.

@aleksandr-kotlyar
Last active March 9, 2023 20:33
Show Gist options
  • Save aleksandr-kotlyar/baf85a765f372e4c5261b52c945ce88f to your computer and use it in GitHub Desktop.
Save aleksandr-kotlyar/baf85a765f372e4c5261b52c945ce88f to your computer and use it in GitHub Desktop.
Open Opera browser with Selenium and webdriver-manager python
import glob
import os
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.opera import OperaDriverManager
def test_operadriver_manager_with_selenium_win():
driver_path = OperaDriverManager().install()
options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.add_experimental_option('w3c', True)
paths = [
f for f in glob.glob(
f"C:/Users/{os.getlogin()}/AppData/Local/Programs/Opera/**",
recursive=True
)
]
for path in paths:
if os.path.isfile(path) and path.endswith("opera.exe"):
options.binary_location = path
web_service = ChromeService(driver_path)
web_service.start()
opera_driver = webdriver.Remote(web_service.service_url, options=options)
opera_driver.get("http://google.com")
opera_driver.quit()
def test_operadriver_manager_with_selenium_linux():
driver_path = OperaDriverManager().install()
options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.add_experimental_option('w3c', True)
options.binary_location = "/usr/bin/opera"
web_service = ChromeService(driver_path)
web_service.start()
opera_driver = webdriver.Remote(web_service.service_url, options=options)
opera_driver.get("http://google.com")
opera_driver.quit()
def test_operadriver_manager_with_selenium_mac():
driver_path = OperaDriverManager().install()
options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.add_experimental_option('w3c', True)
options.binary_location = "/Applications/Opera.app/Contents/MacOS/Opera"
web_service = ChromeService(driver_path)
web_service.start()
opera_driver = webdriver.Remote(web_service.service_url, options=options)
opera_driver.get("https://google.com")
opera_driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment