【问题标题】:AttributeError: 'bool' object has no attribute 'Click'AttributeError: 'bool' 对象没有属性 'Click'
【发布时间】:2022-07-01 01:50:45
【问题描述】:

我正在尝试在 moodle 上自动执行登录过程,但是当我尝试在用户名字段中查找和发送密钥时,我出现了错误 这是我的代码:

from selenium.webdriver.common.by import By
import webbrowser
from selenium import webdriver
driver = webdriver.Chrome(r'D:\Install\chromedriver_win32\chromedriver.exe')
driver.get("https://lms.jspmrscoe.edu.in/?redirect=0")
username = driver.find_element(By.NAME, 'username').is_displayed()
username.Click()
username.send_keys("name*emphasized text*")

代码在找到元素之前工作正常,但是当我尝试通过 .click() 单击它时,它显示错误如下:

AttributeError: 'bool' object has no attribute 'Click'

【问题讨论】:

  • .is_displayed() 根据是否显示该元素返回一个布尔值 True 或 False。你需要检查if那个元素isdisplayed但是你必须检查.Click() 元素本身,而不是isdisplayed的结果

标签: python selenium selenium-webdriver automated-tests


【解决方案1】:

在这一行:

username = driver.find_element(By.NAME, 'username').is_displayed()

is_displayed() 函数被调用。

这将返回 TrueFalse - 一个布尔值。

您不能在 username 上调用 .Click() 函数,因为布尔值没有该函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-06
    • 1970-01-01
    • 2022-12-05
    • 1970-01-01
    • 2020-08-06
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    相关资源
    最近更新 更多