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

标签 python selenium selenium-chromedriver

运行此简单代码时,会打开一个空白页面,其中在 url 中写入“data:,”。 Chrome 驱动程序是正确的版本 (ChromeDriver 81.0.4044.69) 并且与我的 GoogleChrome 版本 (81.0.4044.122) 匹配。 Selenium 也更新了 (3.141.0)

我还将驱动程序的文件夹添加到系统的 PATH 中。 还尝试在 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()

Screenshot.jpeg

最佳答案

在您的代码中,您使用了 driver 而不是 self.driver。请引用以下代码解决您的问题::

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()

关于Python:Selenium Chrome 驱动程序打开空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61437020/

相关文章:

python - 是否可以使用 Anaconda 包作为 Google Cloud Functions 的依赖项?

python - 为 Youtube 自动生成的字幕自动打开脚本

python-3.x - Selenium(Python)-等待使用Chrome Web驱动程序完成下载过程

c# - 如何修复此 C# 问题 没有测试与给定的测试用例过滤器匹配

python - 如何使用 Selenium 和 Chromedriver 查找元素

python - Tensorflow 签名输出占位符

Python pandas 是一种查看哪列包含值并使用其坐标作为偏移量的有效方法

python - 如何在 Django 中为简单用户和 super 用户编写测试用例

java - 问题: Shutterbug Screenshot create a new folder for each screenshot instead of keeping them in 1 folder

python - 使用 pyinstaller 摆脱 chromedriver 控制台窗口