nut*_*hip 6 python selenium hover selenium-webdriver
我想点击悬停后可见的按钮.它的HTML是:
<span class="info"></span>
Run Code Online (Sandbox Code Playgroud)
我用过这段代码:
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()
Run Code Online (Sandbox Code Playgroud)
虽然不行.我得到一个与最后一行代码相关的错误element.click():
selenium.common.exceptions.ElementNotVisibleException: Message: \
u'Element is not currently visible and so may not be interacted with'
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
我打赌你应该等待元素,直到它变得可见.
三种选择:
我会选择第二个选项.
UPD:
在这个通过硒悬浮的特定网站根本不起作用,所以唯一的选择是使用js点击按钮execute_script
:
driver.execute_script('$("span.info").click();')
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.
归档时间: |
|
查看次数: |
10712 次 |
最近记录: |