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.
Related
my goal is to run a python script that uses Selenium to manipulate the chrome browser, directly with Pydroid 3 app on my android smartphone (without a pc connection).
I followed the instructions at the link https://chromedriver.chromium.org/getting-started/getting-started---android to download the appropriate webdriver and set it correctly for Android.
In detail the version of Chrome on my Smartphone (Samsung S10) is 108.0.5359.128 therefore, following what is indicated here:
https://chromedriver.chromium.org/downloads#h.p_ID_32
I downloaded webdriver "chromedriver_linux64.zip" present at the following link:
https://chromedriver.storage.googleapis.com/index.html?path=108.0.5359.71/
But following this example
https://chromedriver.chromium.org/getting-started/getting-started---android#h.p_ID_390 and running the following Python3 script:
from selenium import webdriver
path_to_chromedriver = os.path.dirname(__file__) + '/chromedriver'
print('path_to_chromedriver: ', path_to_chromedriver)
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(path_to_chromedriver, 0, options=options)
driver.get('https://google.com')
driver.quit()
or this one:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
path_to_chromedriver = os.path.dirname(__file__) + '/chromedriver'
print('path_to_chromedriver: ', path_to_chromedriver)
service = Service(path_to_chromedriver)
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://google.com')
I get this error:
path_to_chromedriver: /storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/chromedriver
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 124, in <module>
File "/storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/justwatchScraper.py", line 168, in start
scrolledGenrePage = scrollGenrePageToTheEnd(genrePageURL)
File "/storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/justwatchScraper.py", line 47, in scrollGenrePageToTheEnd
driver = webdriver.Chrome(service=service, options=options)
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
super().__init__(
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
self.service.start()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 106, in start
self.assert_process_still_running()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'
[Program finished]
Can anyone help me or suggest a workaround?
receiving the following error when attempting to run Chrome Driver via my Selenium Test in CodeSpace/Workspace.
Traceback (most recent call last):
File "/workspaces/117965322/SeleniumTest", line 5, in <module>
driver = webdriver.Chrome(service=ser)
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
super().__init__(
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
self.service.start()
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 106, in start
self.assert_process_still_running()
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'
The code I'm running currently is the below:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
ser = Service("/home/ubuntu/.local/lib/python3.10/site-packages/chromedriver")
driver = webdriver.Chrome(service=ser)
driver.get("https://www.google.com")
driver.quit()
I've added the selenium.webdriver.chrome.service line as it removed an issue with the executable path, but not the final Attribute Error?
Any help would be fantastic as have exhausted my Googling capabilities!
Just trying to initially get ChromeDriver working for another project but can't get it to launch due to the above error.
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?
I am try to run a selenium script on firefox using python. But I receive an unclear error. I have read topics about display, but that is not my case.
Command
xvfb-run /usr/bin/python2.7 /var/www/html/selenium-scripts/example.py >> /var/log/selenium 2>&1
Script
from __future__ import print_function
import logging
import time
import datetime
from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/usr/local/firefox/firefox')
display = Display(visible=0, size=(1024, 768))
display.start()
print('>> TEST START')
browser = webdriver.Firefox(firefox_binary=binary, timeout=60)
browser.get("http://www.vandeel.com")
print('>> TEST ENDED')
driver.quit()
display.stop()
Error
>> TEST START
Traceback (most recent call last):
File "/var/www/html/selenium-scripts/example.py", line 16, in <module>
browser = webdriver.Firefox(firefox_binary=binary, timeout=60)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 78, in __init__
self.binary, timeout)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: **The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.**
Please advice
I'm able to run my Python code(main.py) perfectly alright.The problem happens when I use Jenkins to run my Python code( main.py). Jenkins is not able to launch Firefox.
The line
driver = webdriver.Firefox() is throwing an exception line this:
Entering main()
Traceback (most recent call last):
File "main.py", line 21, in <module>
driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: "The browser appears to have exited before we could connect. The output was: \n(process:9287): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed\nError: no display specified\n"
Finished: SUCCESS
############# Code snippet ###########
if __name__ == __main__ :
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("www.google.com")
Are you on windows platform and running Jenkins as a windows service?
If so then the remedy will be to run the Jenkins from the command line.