简体   繁体   中英

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'

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM