gpt4 book ai didi

vba - 无法使用 vba 从 selenium 的下拉列表中进行选择

转载 作者:行者123 更新时间:2023-12-04 22:31:42 26 4
gpt4 key购买 nike

嗨,我是通过 VBA 接触 selenium 的新手,所以我试图通过登录网页导航并将数据提取到 excel 文件中来自动化一个过程。
根据我的研究,首先我通过单击调用下拉菜单,然后选择该选项。

下面是我的代码

Sub Praise()
Dim bot As New WebDriver
bot.Start "chrome"
bot.Get "https://dashboard.stripe.com/login"
bot.FindElementById("email").SendKeys ActiveCell.Value
bot.FindElementById("password").SendKeys ActiveCell.Offset(0, 1).Value
bot.FindElementByTag("form").submit
Application.Wait (Now + TimeValue("0:00:8"))
Set myelement = bot.FindElementByClass("bs-Link", Raise:=False)
If myelement Is Nothing Then
Else
bot.FindElementByClass("bs-Link").Click
End If
bot.FindElementByClass("db-AccountSwitcher-chevron").Click ' to call dropdown
bot.FindElementByClass("Text-color--white Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline").Click ' Error occurs in this line

End Sub

这是调用下拉列表的代码

<div class="db-AccountSwitcher-button Box-root Flex-flex Flex-alignItems--center">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-activeImage">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--dark Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--noWrap Text-display--inline">Masorini.com</span></div>
<div class="Box-root Margin-left--8">
<div class="db-AccountSwitcher-chevron"></div>
</div>
</div>


这是下拉列表的代码

<div class="ScrollableMenu SearchableList-items" id="searchable-list-results-47" role="listbox" style="max-height: 200px;">
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Masorini.com</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Ariavoss</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Bikinimas</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Diva Noche</span></div>
</div>
</div>
</div>
<div aria-selected="true" role="option">
<div>
<div class="Box-root Box-background--blue Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgb(255, 255, 255);"><span class="Text-color--white Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Bootyswim</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Zainno</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Actiwears</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Rockactive</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Cat Lovers</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Chicnuit</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Bootyswim</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Diva Noche</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Bikinimas</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">EpicDevil.co</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">probago.com</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Activepose</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">SiaRose.com</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Sunvoss</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Mosselli</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Aroabikini</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">Swimlemon</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">milewatches</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--fallback"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">stripe-northwrist@massiveshops.com</span></div>
</div>
</div>
</div>
<div aria-selected="false" role="option">
<div>
<div class="Box-root Box-background--white Padding-horizontal--8 Padding-vertical--4 Flex-flex Flex-alignItems--center" style="cursor: pointer; user-select: none;">
<div class="Box-root Margin-right--8">
<div class="db-AccountSwitcher-accountImage Box-root Box-background--white">
<div class="db-AccountSwitcher-accountImage--content db-AccountSwitcher-accountImage--newAccount"></div>
</div>
</div>
<div class="TruncatedText" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><span class="Text-color--default Text-fontSize--16 Text-fontWeight--medium Text-lineHeight--24 Text-typeface--base Text-wrap--wrap Text-display--inline">New account</span></div>
</div>
</div>
</div>
</div>


这是错误代码

enter image description here

最佳答案

我不确定这个点击部分,但你需要从类名中删除空格以消除该错误

bot.FindElementByCss(".Text-color--white.Text-fontSize--16.Text-fontWeight--medium.Text-lineHeight--24.Text-typeface--base.Text-wrap--wrap.Text-display--inline").Click 

目标 Bootyswim
如果单击有效,那么您还应该能够使用:
bot.FindElementByXPath("//*[@role='option'][5]").Click

然后你改变 [5]为您的其他选择。

试试 xpath here并选择其他选项。

关于vba - 无法使用 vba 从 selenium 的下拉列表中进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52228094/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com