How To Enable Built-in Vpn In Operadriver?
Solution 1:
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 tryIPv6:2001:67c:2660:425:2:0:0:3f8
IPv4:77.111.247.26
Second tryIPv6:2001:67c:2660:425:1a:0:0:1a0
IPv4:77.111.247.66
Third tryIPv4:77.111.247.133IPv6:Not detected
Forth tryIPv6: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()
Solution 2:
@Dan-Dev has given an excellent answer and allows you to enable the VPN without any manual intervention.
I would like to share an alternative method that I was trying out in the meantime. This Requires a manual intervention to enable the VPN. Only consider this if the accepted answer is not working for you.
STEPS
- Go to the opera privacy settings page at
opera://settings/privacy
first. - Give a sleep time to allow manual intervention.
- Scroll Down and click on the Enable VPN Button.
- Continue with the rest of your actions/logic.
Code:
from selenium import webdriver
from time import sleep
driver = webdriver.Opera(executable_path=r'path/to/operadriver')
driver.get('opera://settings/privacy')
sleep(30) #use this sleep to maually enable the VPN#The rest of your logic goes below #I am just checking my address from a different url
driver.get('https://whatismyipaddress.com')
driver.quit()
Result:
This is not my IP address. So this will work as well.
Note
I did try to click that button with selenium but was unsuccessful in my attempt. Viewing the page source using driver.page_source
gave me something like this
<dom-module id="settings-startup-url-dialog" assetpath="on_startup_page/" css-build="shadow">
<template><styleinclude="settings-shared"scope="settings-startup-url-dialog"></style><cr-dialogid="dialog"close-text="Close"><divslot="title">[[dialogTitle_]]</div><divslot="body"><cr-inputid="url"label="Site URL"value="{{url_}}"on-input="validate_"spellcheck="false"maxlength="[[urlLimit_]]"invalid="[[hasError_(error_)]]"autofocus=""error-message="[[errorMessage_('Invalid URL', 'Please enter a shorter URL', error_)]]"></cr-input></div><divslot="button-container"><paper-buttonclass="cancel-button"on-click="onCancelTap_"id="cancel">Cancel</paper-button><paper-buttonid="actionButton"class="action-button"on-click="onActionButtonTap_">[[actionButtonText_]]</paper-button></div></cr-dialog></template>
</dom-module>
I was not able to automate that clicking part, but works otherwise. I will update this answer if I am able to do that.
Solution 3:
While this isn't exactly a way to do it in code, it worked for me and I hope it helps you out. Open the full browser settings, choose the Advanced
drop down from the left, and click on Features
. You should see a button that says Connect to VPN when starting browser
. Once you turn it on, every time you use selenium with Opera, you will browse with a VPN.
Post a Comment for "How To Enable Built-in Vpn In Operadriver?"