当Firefox,Selenium和Python中的元素被遮盖时,如何解决元素ClickInterceptedException?
我正在尝试使用Selenium和Python自动化登录Microsoft Planner的过程,并且在提供密码后,我会陷入困境。
在Firefox中,收到的错误是
selenium.common.exceptions.elementClickInterceptedException:消息:元素在点(1089,523)无法单击,因为另一个元素掩盖了它
,我知道有多个帖子,我已经尝试了5种基于它们的方法。我看到了方法1和3中的错误,而所有其他方法都不会抛出示例,但也不会移动最终结果的光标图像 - 请勿单击“ sign in” in'in'
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()
我也尝试使用铬,并获得相同的行为(方法1,3失败,而所有其他人都没有报告错误,但不做这项工作),但是有不同的错误:
selenium.common.exceptions.staleelementreferenceException:消息:陈旧元素参考:元素未连接到页面文档
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版本100.0.0.4896.127(FF0D0695743E65305D7194F9BD309E5E5E1C824AAA0-REFS/BRANCH-HEADS/4896_88@{# 4
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'
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论