我是一个新手 selenium 只是想学习。当尝试打开Chrome浏览器通过ChromeDriver我得到了以下错误:
Traceback (most recent call last):
File "selenium_practise1_chrome.py", line 5, in <module>
driver = webdriver.Chrome()
File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Users\kulokesh\AppData\Local\Programs\Python\Python36\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: unable to discover open pages
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=a lotows NT 6.1.7601 SP1 x86_64)
字符串
尝试了很多谷歌搜索,但没有帮助。下面是我的代码:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('http://www.python.org')
print(driver.title)
型
这不是一个代码处理,但我很困惑我错过了什么在这里.也请建议一些好的在线资源来学习Python Selenium.我的Chrome打开看起来像下面:
1条答案
按热度按时间iibxawm41#
此错误消息...
字符串
.表示 ChromeDriver 无法启动/生成新的 WebBrowser,即 Chrome Browser 会话。
溶液
将参数**
--no-sandbox
**到ChromeOptions()
添加到现有代码中,如下所示:型
其他注意事项
tearDown(){}
方法中调用driver.quit()
,以优雅地关闭和销毁 WebDriver 和 Web Client 示例。