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 python?
Attempt and problem in detail:
I have this script that goes to a website to display my IP address.
from selenium import webdriver
from selenium.webdriver.opera.options import Options
from time import sleep
driver = webdriver.Opera(executable_path=r'/path/to/operadriver')
driver.get('https://whatismyipaddress.com')
sleep(10)
driver.quit()
When I go to this site on the opera browser with VPN enabled, my IP is masked and some other IP address is shown. But my script opens up the browser to display my real IP address.
I have searched almost all questions on OperaDriver on SO as well as on other sites. There seems to be absolutely no documentation or any other questions related to this anywhere.
The closest I got was this feature request on github. The OP says that he was able to make it work by using OperaOptions to load a custom profile. The code posted in the link is
OperaOptions operaOptions = new OperaOptions();
operaOptions.addArguments("user-data-dir", "~/Library/Application Support/com.operasoftware.Opera");
driver = new OperaDriver(operaOptions);
I tried to do this in python and nothing worked out. If it is of any concern I use Ubuntu 16.04, and OperaDriver is downloaded from the official github page. Python version is 3.6.7
and Opera version is 57.0.3098.116
for Ubuntu 16.04 LTS (x86_64; Unity)
.
Opera's free VPN works within the browser Because Opera's free VPN service is built into the desktop and Android browser, it keeps the browsing you do within Opera Browser private, but does not apply to your internet use outside of Opera Browser.
While the Opera GX gaming browser for desktop has a built-in VPN, there is no VPN in Opera GX for Android or in any Opera browser on iPhone or iPad.
Go to the Opera menu and select Preferences. Select Privacy & security and enable the VPN. Once enabled, you will see a grey button in your browser's address field. Click the button to select your virtual location and to review how much data you have used.
There are no fixed limitations on speed or bandwidth for our VPN feature in Opera for Android. However, browsing speeds will depend on the current server load.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With