Chrome版本:68.0.3440.106
Chrome网页驱动程序版本:Chrome驱动程序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)
5条答案
按热度按时间dzhpxtsq1#
使用正确的参数禁用扩展:
uqcuzwp82#
今天我是同样的麻烦,我修复使用:
cld4siwp3#
我最近在使用TeamCity时遇到了这个问题,这是由于chrome(和chromedriver)在执行脚本后没有关闭。插入“taskkill /f /im chrome.exe”和“taskkill /f /im chromedriver.exe”修复了这个问题。
ltskdhd14#
此错误消息...
...表示ChromeDriver无法启动/生成新的WebBrowser,即Chrome浏览器会话。
您的主要问题似乎是chrome二进制文件(即chrome.exe)和关联文件无法从以下默认位置获得/访问:
可能的原因是:
其他注意事项
@Test
。webdriver-manager start
的selenium服务器(不要使用远程会话启动selenium服务器)。piv4azn75#
我们在使用Java、Cucumber、Maven、Serenity和IntelliJ时遇到了这个问题。尝试了所有方法后,解决方案非常简单:
只需以管理员身份运行IntelliJ。