-1

I am trying to design a python bot for fetching my attendance records from my university student portal. This is the code I have written.

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

usernameStr = '<uid>'
passwordStr = '<password>'

browser = webdriver.Chrome('D:/SOFTWARES/Chrome Driver/chromedriver.exe')
browser.get(('https://uims.cuchd.in/uims/'))


username = browser.find_element_by_xpath('/html/body/form/div[3]/div/div/div[2]/div/input[1]')
username.send_keys(usernameStr)

nextBtn = browser.find_element_by_xpath('/html/body/form/div[3]/div/div/div[2]/div/input[2]')
nextBtn.click()

password = browser.find_element_by_xpath('/html/body/form/div[3]/div/div/div[2]/div/input[1]')
password.send_keys(passwordStr)

loginBtn=browser.find_element_by_xpath('/html/body/form/div[3]/div/div/div[2]/div/input[2]')
loginBtn.click()

hamburgerBtn=browser.find_element_by_xpath('/html/body/form/div[4]/header/div[1]/div/span[2]')
hamburgerBtn.click()

# this gives error
academicBtn = browser.find_element_by_xpath("/html/body/form/div[4]/div[1]/div/div[1]/ul/ul[1]")
academicBtn.click()

I am able to successfully login but I get stuck when I have to click an element in element drawer. It shows this error: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

I went through this answer and changed my code to:

academicbutton = browser.find_element_by_xpath("/html/body/form/div[4]/div[1]/div/div[1]/ul/ul[1]")
browser.implicitly_wait(10)
ActionChains(browser).move_to_element(academicbutton).click(academicbutton).perform()

It shows this error: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: [object HTMLUListElement] has no size and location

This is the (academics)button I want to click.

button

I do not know web development. So I can't figure out if there is something different about the element I want to click.

EDIT: I am trying to attach code for the button I want to click from inspect window.

<li data-toggle="collapse" data-target="#3563" class="active collapsed" aria-expanded="false">
                   <a href="javascript:void(0);" class="a-uims-nav">
                   <i></i>
                    " Academics "
                   <span class="arrow">
                    ::before
                   </span>
                    </a>                                      
 </li>

2 Answers2

1

You need to introduce webDriver wait.If You can direct click on that element then use the below code :

wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//li[@data-toggle='collapse']/child::a[1]")))
element.click()

if you do manual hover and the sub menu elements are visible then do this :

menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")

actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
1

Use this code to resolve the error. It is concerned with the xpath you are giving.

academicBtn = browser.find_element_by_xpath(
    "/html/body/form/div[4]/div[1]/div/div[1]/ul/li[1]/a")
academicBtn.click()
Yash Arora
  • 31
  • 1
  • 4