The opera browser has a built-in VPN which allows you to hide your IP while browsing. My question is can the VPN be turned on while using OperaDriver with selenium in pytho
You are trying to use OperaOptions not ChromeOptions, from https://seleniumhq.github.io/selenium/docs/api/py/webdriver_opera/selenium.webdriver.opera.webdriver.html
options: this takes an instance of ChromeOptions
As kaqqao says
"enable VPN from the GUI and the setting got saved in the active profile."
from selenium import webdriver
from time import sleep
# The profile where I enabled the VPN previously using the GUI.
opera_profile = '/home/dan/.config/opera'
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=' + opera_profile)
driver = webdriver.Opera(options=options)
driver.get('https://whatismyipaddress.com')
sleep(10)
driver.quit()
Results:
First try
IPv6: 2001:67c:2660:425:2:0:0:3f8
IPv4: 77.111.247.26
Second try
IPv6: 2001:67c:2660:425:1a:0:0:1a0
IPv4: 77.111.247.66
Third try
IPv4: 77.111.247.133
IPv6: Not detected
Forth try
IPv6: 2001:67c:2660:425:1c:0:0:1fe
IPv4: 77.111.247.68
None of which are my IP and the VPN icon is showing next to the address bar.
UPDATED in response to question.
From https://techdows.com/2016/08/opera-profile-location.html
Simple way to know the profile path of Opera is just type about://about in address bar and check for the Profile line under paths.
On Windows 10 the code looks like this.
from selenium import webdriver
from time import sleep
# The profile where I enabled the VPN previously using the GUI.
opera_profile = r'C:\\Users\\dan\\AppData\\Roaming\\Opera Software\\Opera Stable'
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=' + opera_profile)
options._binary_location = r'C:\\Users\\dan\\AppData\\Local\\Programs\Opera\\58.0.3135.114\\opera.exe'
driver = webdriver.Opera(executable_path=r'C:\\operadriver_win64\\operadriver.exe',options=options)
driver.get('https://whatismyipaddress.com')
sleep(10)
driver.quit()