This question already has an answer here:
How to fix WebDriverException: The browser appears to have exited before we could connect? [duplicate]
(1 answer)
Closed 7 years ago.
I have a simple python script that works fine on my local machine. But if I try to run it on my vps I get an error:
Traceback (most recent call last):
File "test.py", line 15, in <module>
browser = webdriver.Firefox(profile)
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 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.
And here is the script:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('permissions.default.image', 2)
# Set all new windows to open in the current window instead
profile.set_preference('browser.link.open_newwindow', 1)
browser = webdriver.Firefox(profile)
browser.get('http://www.google.com/')
html = browser.page_source
print html
browser.close()
Since there is no GUI for the vps is that what is causing the error?
You have to use xvfb package to run webdriver correctly.
usr/bin/xvfb-run /usr/bin/python myfile.py
Check This link for more detail
Related
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
browser = webdriver.Firefox(executable_path=r'/usr/bin/firefox')
browser.get("http://google.com/")
Ubuntu 16 LTS user here.How to fix this empty window issue after I enter url and is no loaded page there.
Output:
> > Traceback (most recent call last): File "/home/pc/PycharmProjects/calculator/test.py", line 781, in <module>
> browser = webdriver.Firefox(executable_path=r'/usr/bin/firefox') File
> "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py",
> line 164, in __init__
> self.service.start() File "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
> line 98, in start
> self.assert_process_still_running() File "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
> line 111, in assert_process_still_running
> % (self.path, return_code) selenium.common.exceptions.WebDriverException: Message: Service
> /usr/bin/firefox unexpectedly exited. Status code was: 0
You need to provide geckodriver path not firefox. Check your firefox browser version and you can download compatible geckodriver from Here
browser = webdriver.Firefox(executable_path="path of geckodriver")
Sample code
browser = webdriver.Firefox(executable_path="/Users/username/Location/geckodriver")
browser.get("https://google.com")
You can add the path to your webdriver in the PATH system variable
export PATH=$PATH:/path/to/driver/firefox-driver
Add it to /home//.profile file to make it permanent.
Then you dont need executable_path=''
I'm automating one of my regular processes by making a tool which uses Selenium. When I run the script in pyCharm, it works. But after converting it to an executable, it is throwing the error code below.
I looked at and tried some solutions available on the internet but I still can't get it resolved.
I have made two .py files, one main file calls another .py file. I enter the info into the GUI and when I press the submit button, it calls the 2nd file which has the code for downloading the required ChromeDriver version. When the line "ChromeDriverManager().install()" executes, it throws the below error.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
options = Options()
download_dir = r"C:\Users\{}\Documents\Downloaded_Report\\".format(user)
prefs = {'download.default_directory': download_dir, "directory_upgrade": True}
options.add_experimental_option("prefs", prefs)
options.add_argument("--start-maximized")
driver = webdriver.Chrome(ChromeDriverManager().install(),
chrome_options=options)
Error:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1705, in __call__
File "AutoSpeedScript.py", line 28, in send_info_to_download_report
File "openPBMSite.py", line 197, in get_info
File "site-packages\webdriver_manager\chrome.py", line 15, in __init__
File "site-packages\webdriver_manager\driver.py", line 45, in __init__
File "site-packages\webdriver_manager\driver.py", line 18, in __init__
File "site-packages\webdriver_manager\config.py", line 28, in __getattr__
File "site-packages\webdriver_manager\config.py", line 21, in get
File "configparser.py", line 780, in get
File "configparser.py", line 1146, in _unify_values
configparser.NoSectionError: No section: 'ChromeDriver'
I'm running selenium using phanthomjs, the script is running perfectly if when I trigger it as:
python my_script.py
But when I try to using nohup:
nohup python my_script.py &
I got the following error:
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 8
It's probably too late but I just met similar error just with another code and I've found a solution. So, when you run nohup your program's output is redirected to nohup.out, and the file for me was like this:
Traceback (most recent call last):
me/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
File "main.py", line 51, in <module>
Work()
File "main.py", line 41, in Work
TakeImage() # start o 16
File "main.py", line 9, in TakeImage
driver = webdriver.PhantomJS()
File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
self.service.start()
File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 1
The workaround was to go to the
.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py
and comment out line
self.assert_process_still_running()
Specifying the parameters works for me:
driver = webdriver.PhantomJS(executable_path = '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs')
I am new to Selenium and am following the website http://selenium-python.readthedocs.org/
I tried the following bit of code which is there on the website
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
When I run this program, a Firefox instance opens but never loads the page. check snapshot
This is what I have received in the output console
C:\Users\Gauss\Desktop>python test.py
Traceback (most recent call last):
File "test.py", line 4, in <module>
driver = webdriver.Firefox()
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.egg\selenium\webdriver\firefox\webdriver.py", line 78, in __init__
self.binary, timeout)
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.egg\selenium\webdriver\firefox\extension_connection.py", line 49, in __init__
self.binary.launch_browser(self.profile)
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.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: C:\Users\Gauss\AppData\Local\Temp\tmpkpjhnhpb If you specified a log_file in the FirefoxBinary constructor, check it for details.
Could someone please suggest a solution to this issue?
Note: This issue is on my office pc and the same code works fine on my home pc. So some issue with Firefox maybe.
Based on your comments, it looks like the version of Firefox you have is not yet supported by python driver. Currently they support up to v. 38, you have 44.
I am using python selenium webdriver in our framework , of late we have been seeing errors like below
(<type 'exceptions.AttributeError'>,
AttributeError("'unicode' object has no attribute 'text'",)
,<traceback object at 0x00000000037D8D48>)
And also we are seeing this error in our product which has unicode charecters in them.Doesnt happen always happens once in 15 times.
Stacktrace:
self.compare_units_test('Singapore')
line 391, in compare_units_test
self.assertTrue(home_page.is_loaded(), Errors.HOMEPAGE_LOGO_ERROR)
File "", line 32, in is_loaded
"Logo did not load results in 10 seconds")
File "\venv\lib\site-packages\pscore\core\support\ps_wait.py", line 20,in until_visible
self._wait_until_visible(locator, timeout, message, True)
File "venv\lib\site-packages\pscore\core\support\ps_wait.py", line 15, in _wait_until_visible
wait.until(EC.visibility_of_element_located(locator), message=message)
File "\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 66, in until
value = method(self._driver)
File "\venv\lib\site- packages\selenium\webdriver\support\expected_conditions.py", line 72, in __call__
return _element_if_visible(_find_element(driver, self.locator))
File \venv\lib\site- packages\selenium\webdriver\support\expected_conditions.py", line 90, in _element_if_visible
return element if element.is_displayed() else False
AttributeError: 'unicode' object has no attribute 'is_displayed'
2015-09-10 15:56:36 - INFO wd_testcase.py:111 in run : Test Runner: Tearing down test: test_compare_units (tests.test.TestFlightsSearch)
2015-09-10 15:56:36 - INFO wd_testcase.py:48 in tearDown : Test Runner: Attempting to teardown.
2015-09-10 15:56:36 - ERROR wd_testcase.py:125 in run : Traceback (most recent call last):
File \venv\lib\site-packages\pscore\core\wd_testcase.py", line 112, in run
self.tearDown()
File "\venv\lib\site-packages\pscore\core\wd_testcase.py", line 49, in tearDown
WebDriverFinalizer.finalize(self.driver, self.has_failed(), self.logger, self.test_context)
File "\venv\lib\site-packages\pscore\core\finalizers.py", line 28, in finalize
WebDriverFinalizer.finalize_skygrid(driver, test_failed, test_context) File "\lib\site-packages\pscore\core\finalizers.py", line 152, in finalize_skygrid
WebDriverFinalizer.finalise_skygrid_driver_failure(driver, test_context)
File "\venv\lib\site-packages\pscore\core\finalizers.py", line 168, in finalise_skygrid_driver_failure
final_url = driver.current_url
File "venv\lib\site- packages\selenium\webdriver\support\event_firing_webdriver.py", line 201, in __getattr__
raise AttributeError(name)AttributeError: current_url
We are using 2.45 version of selenium and 2.7.7 version of python.
When i dug into webdriver source code found this
try:
str = basestring
except NameError:
pass
which specifically addresses the unicode problem which webdriver was running into.
Any ideas what might be causing this? Help would be greatly appreciated
Found the root cause of the problem, it looked like one of the tests was spawning a new browser window and the subsequent tests were using the dialog window instead of the browser window to do selenium commands. At some point one of the tests performed a driver.quit and when the subsequent tests tried to access driver.something they failed since driver was already killed.