VBA:从网站的下拉列表中单击选项 [英] VBA: Click option on dropdown list from website

查看:151
本文介绍了VBA:从网站的下拉列表中单击选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果它很简单,我是新手,但是我进行了很多研究,却没有找到如何在下拉列表中单击此选项(XBT/USD)的方法: https://ibb.co/jqf7zk

Am sorry if it may be very simple, I am a newbie, but I have researched a lot without finding how to click this option (XBT/USD) inside the dropdown list: https://ibb.co/jqf7zk

我只设法用下面的代码显示列表,但是我不知道如何选择XBT/USD,因为它在html源代码上没有ID.

I only have managed to display the list with the code below, but I don't know how to select XBT/USD because this doesn't have an ID on html source.

Option Explicit
Sub BrowseToSite()

Dim IE As New SHDocVw.InternetExplorer
Dim oSelect As HTMLInputButtonElement
IE.Visible = True

IE.Navigate "https://www.kraken.com/charts"

Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop

IE.Document.getElementById("pairselect-button").Click

End Sub

根据检查元素的HTML代码:

HTML code according to inspect element:

< a tabindex="-1" class="currpairs" data-pair-text="XBT/USD" data-pair="XBTUSD">XBT/USD</a >

预先感谢您的宝贵答复.

Thanks in advance for your valuable response.

推荐答案

您快到了.您已找到下拉菜单.您所需要做的就是单击XBT/USD.我想到的最简单的方法是使用getElementsByClassName,但不必一定要使用它.您也可以使用xpath或标记名找到它们.

You are almost there. You have found the dropdown menu. All you need to do is clicking XBT/USD. The easiest method that comes to my mind is using getElementsByClassName but you dont have to necessarily use it. You can find them by using xpath or tagname as well.

好吧,如果您检查源代码,将会看到很多class="currpairs".如果将鼠标悬停在它们上,您将看到它们属于下拉列表中的每个项目. XBT/USD是列表中的第二项.因此,代码中缺少的部分是:

Well, if you inspect the source you will see there are lots of class="currpairs". If you hover on them, you will see that they belong to each item in dropdown list. XBT/USD is the second item in the list. So the missing part in your code is:

IE.Document.getElementsByClassName("currpairs")(1).Click

注意,我们在获得类currpairs后使用了(1).这是因为计数从列表中的0开始.因此,(0)代表列表中的第一项XBT/EUR,而(1)代表列表中的第二项XBT/USD.

Notice we used (1) after getting the class currpairs. This is because counting starts from 0 in list. So (0) represents the first item XBT/EUR, and (1) represents the second item XBT/USD in the list.

希望这会有所帮助.

这篇关于VBA:从网站的下拉列表中单击选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆