-1

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.

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • If you still need help, please provide a [mcve]. Specifically, it will help if you provide a minimal HTML page that can be used with the script. This should all be inside a single `` tag and include only the pieces necessary to reproduce the problem. In addition, include a complete, runnable python script that illustrates what you are trying to do with selenium. – Code-Apprentice Aug 26 '19 at 20:17

1 Answers1

0

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)
skymon
  • 850
  • 1
  • 12
  • 19
  • Thank you!! That worked. I will be making a loop to see if I could solve the problem that way – Tomas Storås Aug 26 '19 at 20:17
  • Sure, please mark as answer if it worked... – skymon Aug 26 '19 at 20:18
  • Sure! As soon as I have solved the problem. Do you have any suggestions on have I could write the loop. I get thrown out of the loop because it immediately triggers the `is not clickable at point (482, 630). Other element would receive the click:`exception. When executing, inside the loop `edit_button = WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Edit']")))` `edit_button.click()` – Tomas Storås Aug 26 '19 at 20:56
  • Would it be possible to retrieve y coordinate value for the edit button (how?). `y_value_of_edit = function to retrieve y value` `y_offset = y_value_of_edit + 10` `driver.execute_script(f"window.scrollTo(0, {y_offset})")` `edit_button.click()` – Tomas Storås Aug 26 '19 at 21:04
  • Mhh, have you tried the suggestions from the questions that are marked as duplicate of yours? Specifically I'd start changing the `edit_button.click()` to `driver.execute_script("arguments[0].click();", edit_button)` – skymon Aug 26 '19 at 21:05
  • Thank you very much! I'm lacking words to describe how grateful I am. The following function finally did the trick: `driver.execute_script("arguments[0].click();", edit_button)` – Tomas Storås Aug 26 '19 at 21:20