简体   繁体   English

Python:Selenium Chrome 驱动程序打开空白页

[英]Python: Selenium Chrome Driver opens blank page

When running this simple code a blank page opens with 'data:,' written in the url. Chrome driver is the correct version (ChromeDriver 81.0.4044.69) and matches my GoogleChrome version (81.0.4044.122).运行这个简单的代码时,会打开一个空白页面,其中显示“数据:”,写在 url 中。Chrome 驱动程序是正确的版本 (ChromeDriver 81.0.4044.69) 并且与我的 GoogleChrome 版本 (81.0.4044.122) 匹配。 Selenium updated also (3.141.0) Selenium 也更新了 (3.141.0)

I have also added the driver's folder to the systems' PATH.我还将驱动程序的文件夹添加到系统的路径中。 Also tried with http instead of https in the url.还尝试在 url 中使用 http 而不是 https。

from selenium import webdriver

class GoogleBot:
def __init__(self):
    self.driver = webdriver.Chrome(executable_path="C:\Drivers\chromedriver.exe")
    driver.get("https://www.google.es/")


GoogleBot()

截图.jpeg

In your code you have used driver intead of self.driver .在您的代码中,您使用了driverself.driver please refer below code to resolve your issue::请参考以下代码来解决您的问题::

from selenium import webdriver

class GoogleBot:

    def __init__(self):
        self.driver = webdriver.Chrome(executable_path=r"path for chromedriver.exe")

    def googleTest(self):
        self.driver.get("https://www.google.es/")
        self.driver.close()

if __name__ == "__main__":
    GoogleBot = GoogleBot()
    GoogleBot.googleTest()

@DipakBachhav I get no error, Only this. @DipakBachhav 我没有错误,只有这个。 but only after I close the blank Chrome window.但只有在我关闭空白的 Chrome 窗口之后。 (Then i have to end chrome driver process from the task manager) (然后我必须从任务管理器结束 chrome 驱动程序进程)

Traceback (most recent call last):
  File "C:/Users/Ramiro/Desktop/Python/PyCharm/Cursito.py", line 3, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\Ramiro\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\Ramiro\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Ramiro\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Ramiro\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Ramiro\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from chrome not reachable
  (Session info: chrome=81.0.4044.122)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM