首页 > 解决方案 > 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.

标签: excelvbaseleniumdropdown

解决方案


由于两个下拉框相似,您可以获得一个列表或一组元素,而不是单个元素。

下面只是一个演示,可能有语法错误。(对不起,我不擅长 vba)

Dim titles As Object
Set titles = bot.findElementsByClass("highcharts-exporting-group")

For each item in titles
  item.Click
Next item

推荐阅读