excel - How to click on the second instance of drop down box with similar html code - Selenium VBA Excel
问题描述
I am trying to download two xls files from two dropdown boxes which are located in two similar data boxes. The first data box:
<div id="contain" style="height: 400px" data-highcharts-chart="2">
…several containers…
<g class="highcharts-exporting-group" data-z-index="3</g>
The full path:
/html/body/div[2]/div/div[3]/div[1]/div/div[2]/div[1]/div/div[2]/div/div/svg/g[6]
The second data box:
<div id="containB2C" style="height: 400px" data-highcharts-chart="3">
…several containers…
<g class="highcharts-exporting-group" data-z-index="3</g>
The full path:
/html/body/div[2]/div/div[3]/div[1]/div/div[2]/div[2]/div/div[2]/div/div/svg/g[6]
I can click the first dropdown box with the code:
obj.FindElementByClass("highcharts-exporting-group").Click
and select the item:
obj.FindElementByXPath("//*[text()='Download XLS']").Click
But I cannot click the second drop down box in the second data box with similar code. Would appreciate any tips on how to do it.
解决方案
由于两个下拉框相似,您可以获得一个列表或一组元素,而不是单个元素。
下面只是一个演示,可能有语法错误。(对不起,我不擅长 vba)
Dim titles As Object
Set titles = bot.findElementsByClass("highcharts-exporting-group")
For each item in titles
item.Click
Next item
推荐阅读
- html - 如何在一段时间后使用 HTTPS 而不是 HTTP 进行重定向?
- kubernetes - 如何横向扩展已创建的作业?
- python - 解析器 BS4 写入文件
- laravel-mix - 如何使用 Laravel Mix 定义编译文件的目录
- javascript - 为什么 Chrome V8 JavaScript 引擎将“TG-1”到“TG-12”识别为有效日期/时间?
- python - 如何使用关键字和索引提取子字符串?
- r - 如何使用 dcast 更改列名?
- python - 如何使用 Python 和 Pandas 从 Salesforce 的有序字典层次结构中提取数据
- php - 为什么 OpenCart 管理面板设计上的授权逻辑会像这样(奇怪)?
- amazon-web-services - Cloudformation:错误:成员的长度必须小于或等于 20