Python selenium problem with wait till element is clickable and with click link with javascript href [closed]

I wrote script to get data from page and I try improve two functionality. First: I want to change time.sleep(10) to

select = WebDriverWait(driver, 30).until(ec.element_located_to_be_selected((By.NAME, 'capacityReport_length')))

but i get "is not clickable at point (438,86) because another element <div class="mods-content-all-aisles"> obscures it".

Also i can't click <a href = "setting min" href="javascript:void(0)">

Any advice ?


Solution 1:

In order for an element to be directly clickable, it can't be obscured by another element. In the browser, the obscuring element (often the encapsulating element), takes the click event and may or may not pass it through to elements beneath it. In other words, the element you want to click is not directly clickable.

In this case, the element <div class="mods-content-all-aisles"> is blocking you from directly clicking the element you want to click.

You can try to find the obscuring element and click that element at some location to get the behavior you want.

It could also be the case that your wait condition is not sufficient. You probably want to (additionally) use the element_to_be_clickable condition.

wait = WebDriverWait(driver, 10)
element = wait.until(ec.element_to_be_clickable((By.ID, 'someid')))

Alternatively, you can try some of the following ideas:

using javascript to trigger the click:

driver.execute_script("arguments[0].click();", my_element)

You can also try using javascript to retrieve an element from coordinates and clicking it:

coords = (438, 86)
driver.execute_script("document.elementFromPoint(arguments[0], arguments[1]).click()", *coords)

You could also try deleting the element that obscures the element you want to click, but that may end up deleting the element you want to click if it's nested inside of it.

Ultimately, it will be difficult to give definitive answer without the full contents of the page you're working with including the HTML and JS resources. But hopefully this guidance will help you arrive at the solution for this specific webpage.