【问题标题】:TypeError: 'str' object is not callable in driver.title()TypeError: 'str' 对象在 driver.title() 中不可调用
【发布时间】:2020-12-11 11:42:14
【问题描述】:

在下面的代码中,我试图打印标签标题并打开标签,但之后 python 给了我一个 TypeError 并且程序崩溃了。

from selenium import webdriver
path = "C:\Program Files\chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get() # in the parentheses is a link like https://link.com/
print(driver.title())
driver.quit()

有什么问题?我该如何解决?

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver webdriver page-title


    【解决方案1】:

    driver.title

    title 是一个属性,而不是一个方法。它返回当前页面的标题。

    用法:

    title = driver.title    
    

    解决方案

    您需要删除括号。如此有效,代码行将是:

    print(driver.title)
    

    【讨论】:

      猜你喜欢
      • 2015-03-07
      • 2019-03-05
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多