Home > Mobile >  AttributeError: 'bool' object has no attribute 'Click'
AttributeError: 'bool' object has no attribute 'Click'

Time:07-01

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'

CodePudding user response:

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

CodePudding user response:

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