0

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'
1
  • .is_displayed() returns a boolean of True or False depending on whether that element is displayed. You need to check if that element isdisplayed but then you have to .Click() the element itself, not the result of isdisplayed Commented Jun 30, 2022 at 17:50

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

yes this worked and also cleared misconception in my mind , thank you so much
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.