Selenium-Firefox: Firefox browser crashes when running my Selenium script [duplicate] - python

This question already has answers here:
Can't open browser with Selenium after Firefox update
(7 answers)
Closed 6 years ago.
I was running some scripts I had developed in Selenium-Python today. They were working just fine. When I closed out a window & went to re-run a test, the Firefox browser that opened up would crash & my script would fail. This literally happened one second to the next. I wasn't sure what had changed to cause this.
I'm running Selenium 2.53 & Firefox 47 on my machine. Occasionally when I try to run my script again, I will get this run error in Pycharm:
File "C:\Python34\lib\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.
Normally I just get an error when I manually close the crashed FireFox browser that opens. Any ideas as to what occurred?

I also had issues with Firefox 47 and Selenium. You could try reverting back to a previous version of Firefox and disabling updates.
Previous versions of Firefox and instructions on how to disable automatic updates can be found here:
https://support.mozilla.org/en-US/kb/install-older-version-of-firefox

According to
Firefox 47 release notes (June 7, 2016):
Unresolved: Selenium WebDriver may cause Firefox to crash on startup, use Marionette WebDriver instead

I would like to slightly correct previous answer. Working example is below:
Preliminary:
Download geckodriver.zip from https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver;
Extract geckodriver.exe to the directory where this script is located.
Run script:
# -*- coding: utf-8 -*-
import os
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
browser = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=gecko+'.exe')
browser.get('http:///www.google.com')
browser.close()
# browser.quit()

Related

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

Timeout after launching IE using Selenium

I am trying to execute the code below. After launching the provided URL on the IE browser, the next line of code times out and does not get executed.
Please help!
Apps and version:
Selenium: 3.141
Python: 3.8
Pycharm IDE: 2020.1
Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver=webdriver.Ie(executable_path="...\IEDriverServer.exe")
driver.get("https://google.co.in") # Launch is successful.
print(7+7) # This is not executed. The process times out.
I am able to proceed now.
I was using 64bit IE-driver, I tried with 32-bit now which is allowing me to proceed after browser launch.
No time-out observed.
Thanks

python selenium driver.quit() can not quit firefox browser if firefox_profile setted

This problem really confused me a lot.
I'm using python selenium do some automatic work. After the work done, i need to close browser(I must use firefox). And I know driver.close() is to close current window and driver.quit() will close all windows and exit browser. The problem is: it doesn't work for me if i am using python file.py to run my code, but work if I setup the driver in python console, here not work is to say it just close my url, but the firefox browser not exit. All above tests have setted firefox_profile.
More, i found if i don't set firefox_profile the first way to run my code also working. I think maybe it's a bug for firefox_profile. Wish someone to save my day.
My code is just like:
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', download_dir)
profile.set_preference(
'browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
driver = webdriver.Firefox(
executable_path=gecko_dir, firefox_profile=profile)
driver.get(someurl)
driver.quit()# which will close my session, my url, my current window but not exit browser
the versions i'am using:
python 3.5.3
selenium 3.4.3
firefox 55.0.1
geckodriver 0.18.0
While we work with Selenium 3.5.0 with latest GeckoDriver v.0.18.0 and Mozilla Firefox 53.0, the browser window(s) initiated by the WebDriver instance is bound to get destroyed (killed) once you invoke the quit() on the WebDriver instance.
So the blank window which you are seeing may be a result of either some other user interactions or a dangling instance.
Recommendation:
You can consider the following steps to start a clean Test Execution:
Run CCleaner tool to wipe out all the leftovers from your previous executions.
Restart your system to start your Test Execution on a clean OS environment.
Keep the Test Environment isolated from other User Interactions.

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