Python novice. Today in learning python to open Chrome browser using selenium and Webdriver, I encountered two problems
From selenium import webdriver
browser = webdriver.chrome ("Chromium-browser")
browser.get ("http://www.baidu.com")
Then the error is as follows:
Traceback (most recent call last):
File "test.py", line 3, in < module >
Browser = Webdriver. Chrome ("Chromium-browser")
File "/usr/lib/python2.7/selenium/webdriver/chrome/webdriver.py", line, in _ Init_
Self.service.start ()
File "/usr/lib/python2.7/selenium/webdriver/common/service.py", line, in start
Self.assert_process_still_running ()
File "/usr/lib/python2.7/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (Self.path, Return_code)
Selenium.common.exceptions.WebDriverException:Message:Service Chromium-browser unexpectedly exited. Status Code was:0
The reason for this mistake is webdriver. Chrome ("Chromium-browser"), the parameters should not be Chrome browser, but should be chromedriver, so download chromedriver can, my system is Ubuntu 14.04, download decompression after the move to/usr/ Bin directory.
A new problem is encountered when you change the following:
From selenium import webdriver
browser = webdriver.chrome ("Chromedriver")
browser.get ("http://www.baidu.com ")
Traceback (most recent call last):
File "test.py", line 4, in < module>
Browser.get (' http://www.baidu.com ')
File "/usr/lib/python2.7/selenium/webdriver/remote/webdriver.py", line 264, in get
Self.execute (command.get, {' url ': url})
File "/usr/lib/python2.7/selenium/webdriver/remote/webdriver.py", line 252, in Execute
Self.error_handler.check_response (response)
File "/usr/lib/python2.7/selenium/webdriver/remote/errorhandler.py", line 194, in Check_response
Raise Exception_class (message, screen, stacktrace)
Selenium.common.exceptions.WebDriverException:Message:unknown error:unhandled Inspector Error: {"code":-32603, " Message ': ' cannot navigate to invalid URL}
(Session info:chrome=49.0.2623.108)
(Driver info:chromedriver=2.9.248304,platform=linux 3.16.0-30-generic x86_64)
Do not know the specific reasons, welcome to know the friend to tell, on Google saw a friend write code, tried, the result of the problem solved, successfully opened the page.
import os from selenium import webdriver chromedriver = "/usr/bin/chromedriver" Webdriver.chrome.driver "] = chromedriver browser = webdriver. Chrome (' Chromedriver ') browser.get (' http://www.baidu.com ')