类型错误:“str"对象不可通过 Python 使用 Selenium 调用 [英] TypeError: 'str' object is not callable using Selenium through Python

查看:98
本文介绍了类型错误:“str"对象不可通过 Python 使用 Selenium 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行下面显示的代码时出现错误:

When I try to do code shown below I get error :

TypeError: 'str' 对象不可调用

TypeError: 'str' object is not callable

email2_elem = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/input[1]").text()

推荐答案

此错误信息...

TypeError: 'str' object is not callable

...表示你的程序调用了一个 function(),它实际上是一个 property.

...implies that your program have invoked a function() which is actually a property.

根据 selenium.webdriver.remote.webelement text 是一个 property.

因此,您不能将 text() 作为函数调用.因此您会看到错误.

So, you can't invoke text() as a function. Hence you see the error.

您可以使用以下任一解决方案:

You can use either of the following solutions:

email2_elem = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/input[1]").text

  • 使用 get_attribute("innerHTML") 方法:

    email2_elem = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/input[1]").get_attribute("innerHTML")
    

  • 这篇关于类型错误:“str"对象不可通过 Python 使用 Selenium 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆