You need to wait for the button to become clickable or maybe it is not shown on the screen yet, you can try something like this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:Program Files (x86)chromedriver.exe" #path to webdriver executable
wd = webdriver.Chrome(PATH)
urlDepartments = 'https://profiles.ucr.edu/app/home'
wd.get(urlDepartments)
time.sleep(1)
idFirst = 'cdk-accordion-child-'
idNum = 0
idNumStr = str(0)
div = wd.find_element_by_id(idFirst + idNumStr)
button = div.find_elements_by_tag_name('button')
print("Is visible: " + str(element_name.is_displayed()))
time.sleep(3)
button[0].click()
#print(button)
I am trying to access a specific button on a webpage so that I can click it and webscrape what’s on the other side. I’m trying to use Selenium to return a list of buttons under a specific div so that I can click the first one. However, I receive an error upon clicking the 0th index.
I receive the following error:
ElementNotInteractableException: Message: element not interactable
(Session info: chrome=87.0.4280.88)
Am I unable to click elements if they are in a list? Or could this be something else?
Webpage: https://profiles.ucr.edu/app/home
Picture of HTML and desired ID element. I want to click the red “Browse” button:
div and button HTML
Here is the code that I am using, but it returns an error. I commented out the ability to print out the list of buttons:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:Program Files (x86)chromedriver.exe" #path to webdriver executable
wd = webdriver.Chrome(PATH)
urlDepartments = 'https://profiles.ucr.edu/app/home'
wd.get(urlDepartments)
time.sleep(1)
idFirst = 'cdk-accordion-child-'
idNum = 0
idNumStr = str(0)
div = wd.find_element_by_id(idFirst + idNumStr)
button = div.find_elements_by_tag_name('button')
button[0].click()
#print(button)
What are the steps involved to find the red colored Browse button to be visible on the webpage
Not enough info provided. Usually this occurs when the element is hidden, disabled or covered by an overlay. It’s useful to try a wait (element_to_be_clickable ) and that may resolve the error. More info:
I used “wd.find_element_by_id(‘cdk-accordion-child-0’) to find the div that contains four buttons, where the first is the one that I want. I then used div.find_elements_by_tag_name(‘button’) to find the children button of that div tag
So, even though Selenium can detect the button, it cannot click it because it cannot “see it”? Similarly to how a human can assume that a login button for StackOverflow exists before they are able to click it since their page hasn’t fully loaded yet?
Also, I plugged in my variable div into element_name, but I got the same error. Was plugging in this variable there the intended idea?