Milonic菜单:元素在该点不可单击。其他元素将接收cli

2024-03-28 19:37:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试自动选择Milonic菜单中的项目。我使用的代码如下:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
example_menu = driver.find_element_by_id('m_example')
example_menu.click()
# Wait for the "Example Choice" choice to appear
choice_present = expected_conditions.presence_of_element_located((By.LINK_TEXT, 'Example Choice'))
WebDriverWait(driver, 5).until(choice_present)
# Click on "Example Choice"
example_choice = driver.find_element_by_link_text('Example Choice')
example_choice.click()

但是,会引发WebDriverException,并发出类似于以下消息:

^{pr2}$

Tags: fromimportsupportbyexampledriverseleniumelement
1条回答
网友
1楼 · 发布于 2024-03-28 19:37:09

解决方案是使用ActionChains将鼠标移动到菜单项上,但单击Milonic链接:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Firefox()
example_menu = driver.find_element_by_id('m_example')
example_menu.click()
# Wait for the "Example Choice" choice to appear
choice_present = expected_conditions.presence_of_element_located((By.LINK_TEXT, 'Example Choice'))
WebDriverWait(driver, 5).until(choice_present)
# Use an action chain to move to the "Example Choice" but click on the
# Milonic menu link
example_choice = driver.find_element_by_link_text('Example Choice')
mmlink1 = driver.find_element_by_id('mmlink1')
action_chain = ActionChains(driver)
action_chain.move_to_element(example_choice)
action_chain.click(mmlink1)
action_chain.perform()

相关问题 更多 >