is not clickable at point (111, 102). Other element would receive the click: <div role="heading" aria-level="1" class="vertical">...</div>
正如例外情况所示,selenium 无法单击所需的元素(Database Manager),因为某些其他元素覆盖在所需的元素上。如果无法访问实际页面,我无法告诉您如何准确地摆脱覆盖元素。但您可以尝试以下几件事:
不确定您是否已最大化窗口,有时最大化窗口不会造成任何阻碍。如果您还没有尝试过,请在您的代码中尝试一下。
driver.maximize_window()
使用操作链与菜单和子菜单进行交互。尝试使用 ActionChain 的
click()
方法,而不是 Selenium 的 move_to_element
方法。示例代码如下:
from selenium.webdriver import ActionChains
# Create actions object
actions = ActionChains(driver)
# Store the desired element into a variable called element
element = driver.find_element(By.XPATH,"//*[@class='drawer-menu']//child::div[1]//div[text()='Database Manager']")
# Click on element using ActionsChains
actions.move_to_element(element).perform()
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
...
# Create wait object with 10s wait time
wait = WebDriverWait(driver, 10)
# Below line will wait for 10s until the state of the desired element is clickable
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@class='drawer-menu']//child::div[1]//div[text()='Database Manager']"))).click()
Javascript
来执行点击,而不是 Selenium 的 click()
。示例代码如下:import time
...
time.sleep(5)
element = driver.find_element(By.XPATH,"//*[@class='drawer-menu']//child::div[1]//div[text()='Database Manager']")
driver.execute_script("arguments[0].click();", element)