Control Vivaldi browser - python

I want to manage the tabs of Vivaldi (Windows) using Python: get URLs, focus a specific tab, open, close, reload...
This post asks how to open Vivaldi, and my script does it, but not when/how it's supposed to do it:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import os
current_user = os.getlogin()
s = Service(rf"C:\Users\{current_user}\AppData\Local\Vivaldi\Application\vivaldi.exe")
driver = webdriver.Chrome(service=s)
The last line opens a new (unwanted) window of Vivaldi, which baffles me because I thought it should only declare a variable, and then nothing happens for some minutes. Finally I get this error:
Traceback (most recent call last):
File "C:\Users\Negozio\Dropbox\D.Apps\Negozio\Conta\test.py", line 7, in <module>
driver = webdriver.Chrome(service=s)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in __init__
self.service.start()
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 105, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:\Users\Negozio\AppData\Local\Vivaldi\Application\vivaldi.exe
I thought that Vivaldi should open with driver.get("http://url.com"), am I wrong? What's happening here, and above all how can I manage Vivaldi with Python?

Related

webdriver error "urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// or https://"

I'm new to python, when I want to run following simple code I got error:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.whatsmyip.org")
error:
Traceback (most recent call last):
File "C:\Users\Saeed\Desktop\insta bot\instagram.py", line 3, in <module>
browser = webdriver.Firefox()
File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 177, in __init__
executor = FirefoxRemoteConnection(
File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\firefox\remote_connection.py", line 27, in __init__
RemoteConnection.__init__(self, remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 155, in __init__
self._conn = self._get_connection_manager()
File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 143, in _get_connection_manager
urllib3.ProxyManager(self._proxy_url, **pool_manager_init_args)
File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\poolmanager.py", line 480, in __init__
raise ProxySchemeUnknown(proxy.scheme)
urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// or https://
Thank you in advance for your guidance.
This error appears when your client code (your test) attempts to send a command to a WebDriver service. Since it is REST (over http) Selenium takes the proxy that is defined in environment variable for corresponding protocol:
def _get_proxy_url(self):
if self._url.startswith('https://'):
return os.environ.get('https_proxy', os.environ.get('HTTPS_PROXY'))
elif self._url.startswith('http://'):
return os.environ.get('http_proxy', os.environ.get('HTTP_PROXY'))
Looks like the value that is assigned to one of (or both) those vars is not a proper URL.
The solution would be:
either to fix the URL
or to toggle ignore_local_proxy_environment_variables in FirefoxOptions

Chromedriver: "FileNotFoundError: [WinError 2] The system cannot find the file specified" Error

Have looked for an answer, but couldn't find anything. It seems insistent on saying it can't find the file specified and then checks PATH, but can't see it even then :/ I've put the directory in PATH: http://imgur.com/a/ZP59w
Program:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com/")
Error:
Traceback (most recent call last):
File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site- packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\dilri\AppData\Local\Programs\Python\Python36- 32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\dilri\AppData\Local\Programs\Python\Python36- 32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "H:\temp.py", line 2, in <module>
driver = webdriver.Chrome()
File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site- packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site- packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
If anyone could help that would be greatly appreciated.
I had the same problem and solved it by using Options method.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\Program Files (x86)\Google\Chrome Dev\Application\chrome.exe"
driver = webdriver.Chrome(chrome_options=options, executable_path=r"C:\Program Files (x86)\Google\chromedriver.exe", )
driver.get("https://www.google.com/")
Hope it solved your problem.
You could try passing it the path directly.
So I have the webdriver file on my dekstop so:
webdriver.Chrome('C:/Users/adam/Desktop/chromedriver.exe')
You can get the webdriver here.
You can use the following :
from selenium import webdriver
browser = webdriver.Chrome(r"*your path here*")
How to get path?
If on windows system go to the extracted location of the webdriver press shift key and select Copy as Path
enter image description here
Download the webdriver you want here:
https://selenium-python.readthedocs.io/installation.html#drivers
Unzip the folder you just downloaded, take the executable file (let's say chromedriver.exe) and put it somewhere (let's say in "C:\Users")
Go back into your python code and change your line to :
driver = webdriver.Chrome(executable_path=r'C:\Users\chromedriver.exe')
It should work now

python selenium does not scale with firefox - Message: Can't load the profile. Profile Dir

Why does this happen using selenium with python and firefox? Selenium cant scale to a simple loop. Why cant firefox scale? Over time it decides to thow an error and quit.
Mozilla Firefox 45.0
selenium.version
'2.53.2'
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
mylist = ['page1','page1',...,'pageN']
while True:
for data in mylist:
browser = webdriver.Firefox()
try:
myfunc(data) # Code that uses selenum to fetch pages
except:
pass
browser.quit()
time.sleep(60)
No handlers could be found for logger "sentry.errors.serializer"
Traceback (most recent call last):
File "platrieveerp.py", line 231, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 103, in __init__
self.binary, timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium-2.53.2-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 106, in _wait_until_connectable
% (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmpOgsKOx If you specified a log_file in the FirefoxBinary constructor, check it for details.
Selenium is not failing while running the loop, it is failing at webdriver.Firefox(). The error is recognized when the connection times out at a certain time after line 231 when the script still cant recognize an open firefox application.
It is just a bug in selenium when running with a headless browser. To get a working version of selenium, run
sudo pip install -U selenium
This should be a similar issue:
Selenium: FirefoxProfile exception Can't load the profile

Selennium Python can't load the profile Iceweasel

I am trying to run Selenium from the command line with Python. I have ice weasel installed n a raspberry pi. This is my code to initialise it:
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Firefox()
However, whenever I try to run the file, I get the following error:
Traceback (most recent call last):
File "Minecraft.py", line 5, in <module>
driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 103, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.

Error while Running a WebDriver using Python script

I had a problem running executing a Webdriver using a script in python using the library selenium. I have posted the sample code scenarios as well as the corresponding error thrown while executing.
Code Scenario:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
Error Scenario:
Traceback (most recent call last):
File "C:/Users/Kaushik/Desktop/IMC DEVELOPER TEST/Sample.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 59, in __init__
self.binary, timeout),
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 60, in launch_browser
self._start_from_profile_path(self.profile.path)
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 83, in _start_from_profile_path
env=self._firefox_env).communicate()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 87] The parameter is incorrect
I coudnt understand the Error thrown. I just need to use the selenium library to retrieve a dynamic data from a website using a python script.
There is nothing wrong with your code, it works fine for me.
Do you have firefox installed? if not, you can use a different browser. for example:
driver = webdriver.Ie
or
driver = webdriver.Opera

Categories

Resources