繁体   English   中英

Python Selenium 键盘动作移动太快

[英]Python Selenium keyboard actions move too fast

我试图通过价格图表上的烛台来读取价格数据。 这是我的部分代码 -

close_prices = []
    While True:
        close_p = driver.find_element_by_xpath(close_path).text
        close_prices.append(close_p)
        actions = ActionChains(driver)
        actions.send_keys(Keys.ARROW_LEFT).perform()

我的想法是当我完成一个烛台的解析时,我可以按 LEFT 到 go 到第二天的烛台。 但是,我发现通过使用 Keys.ARROW_LEFT,它只是移动得太快(或者移动范围很大),它在这之间跳过了几天。 当我手动按键盘上的左键时,图表工作正常。 (即每按一次移动 1 天)在 Selenium 中,它不像我那样工作。 (它移动了几天)

我试图询问是否有任何方法可以控制键盘按键的“移动”。 即让它移动'更少'

在驱动程序中存在的每个操作之前使用 implict_wait(),您也可以使用 webdriverwait

尝试将close_p定义为:

close_p = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, close_path))).text

WebDriverWait 需要这些导入:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM