0

I have already viewed three StackOverflow solutions to almost this problem, but can't figure out how to apply it to an already-fetched web element.

Answer 1

Answer 2

Answer 3

Here is a sample of my current code:

def filter_shaded(tr_element):
    td_list= tr_element.find_elements(By.CLASS_NAME, "row-major-td")
    for td in td_list:
        if 'row-major-td-shaded' not in td.get_attribute("class"):
            return td
clickable_element = filter_shaded(...)
driver.implicitly_wait(3) # wait for element to be clickable
clickable_element.click() # here is the problem, sometimes getting ElementNotInteractableException

Essentially, I have a bunch of td elements inside of a table row. All but one of the elements is shaded. I use this function to "pick out" the unshaded element.

Now, I want to be able to click the unshaded tr element, but I have been having some issues with using a plain fixed delay such as driver.implicitly_wait(3). Sometimes the element is clickable long before 3 seconds and sometimes 3 seconds is not long enough for it to become clickable.

The only issue with the existing answers is that the code for locating the element is integrated into the wait code.

The solutions I posted above all suggest something along the lines of

element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.ID, "my-id")))

element.click();

The above code locates an element by its ID and waits for it to become clickable. In my case, however, I have a custom function that filters out a single WebElement object and returns it (clickable_element in my original code). How can I tell Selenium to wait for an already-found WebElement to become clickable before clicking (and thereby avoiding any ElementNotInteractableExceptions)?

i.e.

def filter_shaded(tr_element):
    td_list= tr_element.find_elements(By.CLASS_NAME, "row-major-td")
    for td in td_list:
        if 'row-major-td-shaded' not in td.get_attribute("class"):
            return td
clickable_element = filter_shaded(...)
??? driver.wait_for_element_to_be_clickable(clickable_element) ??
clickable_element.click()

I'd rather not resort to hard coding or approximating a delay, since the elements can take anywhere from 0.5 to 11 seconds to become clickable and upping the wait time to 11s would be catastrophic for my runtime.

  • I'm not clear on something; aren't buttons supposed to be loadable once you load the webpage up in general? If not, please be a little more specific about that. – 1BL1ZZARD Apr 14 '22 at 00:22
  • @1BL1ZZARD These are not buttons; they are dynamically generated td elements that have an arbitrary onclick attribute associated with them. To the best of my understanding, the ElementNotInteractableException is thrown whenever the td element's click functionality has not yet been generated dynamically. It takes a few seconds for whatever backend script this site uses to load in the onclick code for each td element. See [here](https://www.edureka.co/community/55217/resolve-elementnotinteractableexception-selenium-webdriver) – Java Weenis Apr 14 '22 at 01:03

0 Answers0