How to resolve ElementClickInterceptedException when element is obscured in Firefox, Selenium and Python?

291 Views Asked by At

I'm trying to automate the process of logging into Microsoft Planner using Selenium and Python and I'm getting stuck at the step after providing a password.

In Firefox, the error received is

selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (1089,523) because another element obscures it

I understand that there are multiple posts with this question and I have tried 5 approaches based on them. I see the error in Approach 1 and 3, while all the other approaches don't throw an excpetion, but also do not move the cursor Image of final result - doesn't click on 'Sign in'

enter image description here

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Firefox() 
# driver = webdriver.Chrome() 
driver.maximize_window()

url = 'https://tasks.office.com/company_domain/group_id'
email_id = "email_id_registered_for_microsoft_planner"
password = "password"

driver.get(url)
driver.implicitly_wait(2)
driver.find_element(By.ID, "i0116").send_keys(email_id)
driver.find_element(By.ID, "idSIButton9").click()
driver.implicitly_wait(2)
driver.find_element(By.ID, "i0118").send_keys(password)
driver.implicitly_wait(2)

# Approach 1
# element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "idSIButton9")))
# element.click()

# Approach 2
# element = driver.find_element(By.ID, "idSIButton9")
# driver.execute_script("arguments[0].click();", element)

# Approach 3
# WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "idSIButton9"))).click()

# Approach 4
# actions = ActionChains(driver)
# actions.send_keys(Keys.TAB * 2)
# actions.perform()

# Approach 5
# element = driver.find_element(By.XPATH, '//*[@id="idSIButton9"]')
# ActionChains(driver).move_to_element(element).click().perform()

I tried this with Chrome as well and get the same behavior (approach 1, 3 fail while all others don't report an error but don't do the job) but with a different error:

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

I am using

  • Firefox version 99.0.1, Chrome version 100.0.4896.127
  • Python 3.8.10
  • Selenium 4.1.3
  • Geckodriver version 0.31.0, Chrome driver version 100.0.4896.127 (ff0d0695743e65305d7194f9bd309e5e1c824aa0-refs/branch-heads/4896_88@{#4})
  • Ubuntu 20.04.3 LTS
0

There are 0 best solutions below