7

我想单击悬停后可见的按钮。它的html是:

<span class="info"></span>

我使用了这段代码:

import selenium.webdriver as webdriver
from selenium.webdriver.common.action_chains import ActionChains

url = "http://example.com"

driver = webdriver.Firefox()
driver.get(url)
element = driver.find_element_by_class_name("info")
hov = ActionChains(driver).move_to_element(element)
hov.perform()
element.click()

但它不起作用。我收到与最后一行代码有关的错误element.click():

selenium.common.exceptions.ElementNotVisibleException: Message: \
u'Element is not currently visible and so may not be interacted with' 

请问有什么建议吗?

4

1 回答 1

11

我打赌你应该等待元素直到它变得可见。

三个选项:

我会选择第二个选项。

升级版:

在这个特定站点上,通过 selenium 悬停根本不起作用,因此唯一的选择是使用 js via 单击按钮execute_script

driver.execute_script('$("span.info").click();')

希望有帮助。

于 2013-05-30T08:35:10.033 回答