WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1 - python

I want to run selenium in google colab i ran the following code:
!apt update
!apt install chromium-chromedriver
!pip install selenium
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# open it, go to a website, and get results
wd = webdriver.Chrome(options=options)
wd.get("https://www.whoscored.com")
print(wd.page_source) # results`
the result expected is the page source being printed out instead i get this error in my notebook:
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
Here is the link of the notebook:
https://colab.research.google.com/drive/13oUHGDc6uy-4vJ1XnRdEcojoFoIToV75
i tried changing the webdriver to firefox but i get a different error memory related stuff:
src/tcmalloc.cc:332] Attempt to free invalid pointer 0x24680020c5d0

I found out the solution from Selenium use chrome on Colab got unexpectedly exited.
Looks like it was a runtime issue. Changing it and following the steps in the link helped and I executed the code there to fix the problem

Related

My selenium script (in Python) for chrome runs but does nothing

vscode says it run but it does nothing. My pip is up to date and i installed selenium with the command prompt. i have a valid path (i think) for chromedriver. Here's my code:
from selenium import webdriver
chromedriver = "C:Users/P-Lou/Downloads/chromedriver.exe"
driver = webdriver.Chrome(chromedriver)
driver.get("http:google.com")
The result is this:
[Running] python -u "w:\Python\Seletest\app.py"
[Done] exited with code=0 in 0.067 seconds
I tried this code by only changing the browser to firefox and removing the chromedriver = part and it worked fine, you might be running the browser in headless mode, thats why nothing pops up. You can change that using The Chromedriver.options(set_headless="false")
(not sure if that is the right code, you can check yourself here)
Presuming the ChromeDriver binary location being C:\Users\P-Lou\Downloads on your windows system you can use the following solution:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Users\P-Lou\Downloads\chromedriver.exe')
driver.get("http:google.com")

I can't get Opera to work on selenium python

I am trying to get Opera to work but there is always an error
I followed this thread, and have exactly the same issues Unable to launch Opera using Python Selenium
They didn't solve the problem
Then same OP did this URL opening fails with Opera using python selenium library and was closed because of reposting the same issue (was not the same issue, now it has another error)
this time is this one:
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
options.binary_location = OperaPath #path to .exe
driver = webdriver.Opera(options=options, executable_path= OperaPath)
Opera.exe unexpectedly exited. Status code was: 0
operadriver=86.0.4240.80
Opera 72
Windows 10, 64 bits
Python 3.8.1

Python 3.4 Selenium handle chromedriver exception

I'm using selenium for python with chromedriver. Unfortunately I havn't found a way to handle errors raised by chromedriver in python!
If I use selenium to open any Webseite:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
opts = Options()
prefs = {"profile.managed_default_content_settings.images": 2}
opts.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=opts)
driver.delete_all_cookies()
driver.get("https://www.google.de/")
#Some more actions
driver.close()
And while the script is running if I close the browser window (manually), I get the following error:
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64)
If I put the python code above entirely in a try/except bracket, if chrome brakes, the exception is not executed! Instead the entire programm brakes!
Is there a way to handle the error raised by chromedriver in python?
Thanks for your advise!
EDIT:
I guess my question wasn't expressed very well. My script is working fine, I just want to handle the exception if someone closes the browser window manually. For now my entire python tool including my gui crashes...
There is a bug in selenium right now when you use driver.close() as the last step of your script. You should be using driver.quit(). driver.close() is to just close the current window (tab) and leave the browser open. driver.quit() tells selenium to quit the chromedriver service as well
This solution works with me:
sudo apt-get install chromium-chromedriver
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")

Selenium webdriver seems not working properly with Firefox 49.0. Am I missing something?

I have gone through previous questions but did not find anyone else running into my issue.
This simple code hangs
from selenium import webdriver
d = webdriver.Firefox();
The browser gets launched, but it just hangs there. After sometime, it crashes and I get the error
selenium.common.exceptions.WebDriverException: Message: Can't load the profile.
Profile Dir: /tmp/tmpn_MQnf If you specified a log_file in the
FirefoxBinary constructor, check it for details.
I have Firefox49 on Ubuntu 14.04 LTS. I had selenium 2.53.6 and reading a previous post, I upgraded to selenium 3.0.0.b3. I also downloaded geckdriver and put it in /usr/bin
It looks like I was still running older version of selenium. But when I uninstalled that and installed selenium 3.0.0.b3, I see the following error -
selenium.‌​common.exceptions.We‌​bDriverException:
Message: Service geckodriver unexpectedly exited. Status code was: 2
What am I missing?
Try renaming the downloaded Gecko Driver to Wires and Set the Capabilities as mentioned Below.
System.setProperty("webdriver.gecko.driver", "//home//.....//BrowserDrivers//wires");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
Driver = new MarionetteDriver(capabilities);
I tried with the Above code on FireFox 49 on Linux Ubuntu 14.04 LTS... Code Works Fine For Me in Java..
Also try to downgrade the selenium WebDriver from Beta to 2.53 as Beta version is unstable..

Page is not loaded in Selenium WebDriver using Python on Windows

I am using Python 3.5 on a Windows computer. When I run this code on my Mac it works perfect, no issues what so ever. But when I bring the code to my Windows computer it doesn't work.
Basically a blank page is shown instead of the home page. I don't get any error messages.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.google.com')
cookies = driver.get_cookies()
print(cookies)
Once I close the web browser I get this message in the shell:
"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.
From what I've been able to find online (most is for Java) it looks like I may need to setup a profile? Is this correct and could anyone help with this?
It looks like your client doesn't have the fix for the new switch to launch the gecko driver:
https://github.com/SeleniumHQ/selenium/commit/c76917839c868603c9ab494d8aa0e9d600515371
Make sure that you have the latest beta version installed (selenium-3.0.0b2) if you which to use the geckodriver v0.10.0 and above:
pip install -U selenium --pre
Note that you need the --pre flag to install the beta version.

Categories