Chrome版本:68.0.3440.106
Chrome网络驱动程序版本:ChromeDriver 2.41.578737
Python版本:Python 3.5.2
我用python编写这段代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
o = webdriver.ChromeOptions()
o.add_argument("disable-extensions");
o.add_argument("--start-maximized");
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
几秒钟后,chrome打开,并显示以下错误:
直到我关闭chrome并得到此异常,什么都没有发生:
Traceback (most recent call last):
File ".../game.py", line 8, in <module>
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
(unknown error: unable to discover open pages)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)
答案 0 :(得分:0)
使用正确的参数禁用扩展名:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
o = Options()
#o.add_argument("--disable-extensions"); #here
o.add_experimental_option("useAutomationExtension", false); #you can try this as well
o.add_argument("--start-maximized");
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",chrome_options=o)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
答案 1 :(得分:0)
此错误消息...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
(unknown error: unable to discover open pages)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...表示 ChromeDriver 无法启动/产生新的 WebBrowser ,即 Chrome浏览器会话。
您的主要问题似乎是 chrome 二进制文件(即 chrome.exe )和关联的文件在以下默认位置不再可用:
C:\Program Files (x86)\Google\Chrome\Application\
可能的原因是:
如果您在non-standard location上安装了 Chrome浏览器,则您need to会这样做:
opt = webdriver.ChromeOptions()
opt.binary_location("/path/to/other/chrome/binary");
您在这里找到有关Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome
@Test
。webdriver-manager start
运行selenium服务器(不要使用远程会话启动selenium服务器)。答案 2 :(得分:0)
今天我遇到了同样的麻烦,并且使用以下方法解决了问题:
$('#clearFormButton').click(function(){
ResetForm();
$('#hiddenJobId').val(@Session["jobid"]);
});