attributeError:' bool'对象没有属性' click'

发布于 2025-02-11 22:29:06 字数 568 浏览 3 评论 0原文

我正在尝试在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'

i'm trying to automate a login process on moodle but when i try to find and send keys in the username feild is thsows me error
here is my code:

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*")

the code works fine till the finding of the element but when i try to click on it by .click() it shows a error is like this:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秉烛思 2025-02-18 22:29:06

在此行中:

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

is_displayed()函数被调用。

这返回truefalse - 布尔值。

您不能在.click()函数用户名上调用函数,因为布尔值没有该功能

In this line:

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

the is_displayed() function is called.

This returns True or False - a boolean.

You cannot call the .Click() function on username since booleans don't have that function

客…行舟 2025-02-18 22:29:06

您正在调用单击布尔值,这是解决方案:

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

#in case you want to click when username is diplayed
# do this
if username.is_displayed():
  username.Click()
  username.send_keys("name*emphasized text*")

You are calling Click on a Boolean, here is the solution:

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

#in case you want to click when username is diplayed
# do this
if username.is_displayed():
  username.Click()
  username.send_keys("name*emphasized text*")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文