Skip to main content
 首页 » 编程设计

python之使用 Selenium Actionchains 时指定 Actions 之间的等待时间

2025年05月04日9Renyi-Fan

ActionChains 是使用 Selenium 时非常方便的方法。 它工作得很好,我唯一缺少的是如何在操作之间插入等待时间。

我将从官方的 google Selenium 文档中获取相同的示例。 https://selenium.googlecode.com/git/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html

menu = driver.find_element_by_css_selector(".nav") 
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1") 
 
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform() 

我正在寻找一种在两个操作之间插入等待时间的方法

ActionChains(driver).move_to_element(menu)**(..wait some seconds)**.click(hidden_submenu).perform() 

谢谢!

请您参考如下方法:

我试过了,似乎有效

from selenium import webdriver  
 
action = webdriver.ActionChains(driver) 
 
action.pause(3) 
 
action.perform() 
 
driver.close()