selenium - 如何在不可见元素上设置日期
问题描述
我正在尝试在 VBA excel 宏中使用 selenium for chrome 从网站读取数据。
https://www.eex.com/en/market-data/power/futures
我需要有关意大利期货的数据,因此我打开了页面:
driver.Get "https://www.eex.com/en/market-data/power/futures#%7B%22snippetpicker%22%3A%22EEX%20Italian%20Power%20Futures%22%7D"
driver.Wait 1000
driver.FindElementByXPath("//input[@class='btn bordered uo_cookie_btn_type_1']").Click
接下来,我必须设置日期,但该元素不可见:
driver.FindElementByXPath("//input[@class='mv-input-box']").Clear
driver.FindElementByXPath("//input[@class='mv-input-box']").SendKeys ("2020-06-19")
这不起作用:
Run-time error-12
Element is not currently interactable
我不知道如何点击图标来设置日期:
<div class="mv-button-base mv-button-image mv-stack-block mv-hyperlink-button mv-calendar-icon"><div>
</div><svg viewBox="0 0 22 17" class=""><path d="M16,4H14V0h2ZM13,1H9V3h4Zm4,0V3h3V15H2V3H5V1H0V17H22V1ZM8,0H6V4H8ZM8,9H4V5H8ZM7,6H5V8H7Zm6,3H9V5h4ZM12,6H10V8h2Zm6,3H14V5h4ZM17,6H15V8h2ZM4,10H8v4H4Zm1,3H7V11H5Zm8,1H9V10h4Zm-1-3H10v2h2Zm6,3H14V10h4Zm-1-3H15v2h2Z"></path></svg></div>
解决方案
我通过添加 Post.IsDisplayed 解决了这个问题:
For Each Post In driver.FindElementsByXPath("//input[@class = 'mv-input-box']")
If Post.Value = Year(Date) & "-" & Format(Month(Date), "00") & "-" & Format(Day(Date), "00") And Post.IsDisplayed Then
Post.Clear
Post.SendKeys ("2021-25-01")
Post.Click
driver.Wait 2000
Exit For
End If
Next Post
推荐阅读
- sass - 在 sass 中导出变量
- c# - ExcelMapper - 根据条件跳过行
- javascript - html2canvas 和 jsPDF 使用 morris.js 图表导出为 PDF 时的 Safari 问题不会出现
- rest - 在 symfony 4 中与 Rest api (ionic mobil app) 一起实现 Oauth
- python - 根据位置将嵌套列表中的元素提取到单独的列表中
- service - 服务结构:约束服务在某些节点上单独运行
- .net - 通过慢速连接以编程方式按顺序保存会挂起 MS Project
- php - 在 Woocommerce 中删除没有价格的可变产品的添加到购物车
- c++ - 从类返回不正确的值
- java - maven-release-plugin:2.5.1:perform failed: 执行时遇到 API 不兼容