How to solve element is not clickable at point in Selenium using Python

364 Views Asked by At

I am testing a script where I run through about 200 pages. Each page contains an edit button that I need to click on. In about half of the pages this is successfully done, but on the other half I receive an error saying that another element would receive the click.

I know why the error is produced, but I don't know how to solve it.

There is a tab that sometimes blocks the edit button completely (depending on how long/wide the page is and where the edit button is located).

Not clickable Clickable

I have tried a lot of different suggestions on similar issues, but non of the once I have tried has worked for me. Especially these suggestions seemed promising:

Debugging "Element is not clickable at point" error

HTML for the edit button

<div class="aikis-task-portlet-buttons-panel-button" style="">  
    <input type="button" value="Edit" 
 onclick="_aikistaskgeneric_WAR_aikistaskportlet_INSTANCE_6mbS_openFlashEditMode()" style="width: 85px">     
</div>

HTML for the tab that gets in the way

<div id="userVoicelink" onclick="__displayUserVoicePanel()">    
   Suggestions for improvement
</div>

Q: Would it be possible to make it invisible somehow?

The current code that I have is:

edit_button = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Edit']")))
driver.execute_script("arguments[0].scrollIntoView();", edit_button)
edit_button.click()

The exception that is produced is:

ERROR:root:Message: unknown error: Element <a data-toggle="tab" href="#settings">...</a> is not clickable at point (352, 31). Other element would receive the click: <div id="curtain" style="opacity: 0.301426;">...</div>

By using driver.execute_script("window.scrollTo(0, 350)") and changing "350" to different values I am able to make some buttons clickable. The problem is that the edit button is not on the same place on all the pages. One solution could be to make loop with the function, increasing the Y value, while at the same time checking if the button is clickable/visible. So I tried that, but the following code produces the following error:

    y = 350
    driver.execute_script("window.scrollTo(0, y)") 

WebDriverException: unknown error: y is not defined

Q: Would it be possible to get the coordinates of the button and then by using for example driver.execute_script("arguments[0].scrollIntoView();", edit_button) or driver.execute_script("window.scrollTo(0, 350)") But offset the position so it would scroll slightly below the edit button?

Btw, I am using chromedriver, but I am experiencing the same problem when trying geckodriver.

1

There are 1 best solutions below

6
On BEST ANSWER

Regarding your last error message, it looks to me that you're not setting the y value but just the character "y". Assuming you're using Python 3, this should solve that:

y = 350
driver.execute_script(f"window.scrollTo(0, {y})")

More "direct", though a little less pythonic would be:

y = 350
driver.execute_script("window.scrollTo(0, " + str(y) +")")

Edit: As per the possible duplicates, you could also try to modify your code to click the button via JavaScript:

edit_button = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Edit']")))
driver.execute_script("arguments[0].scrollIntoView();", edit_button)
driver.execute_script("arguments[0].click();", edit_button)