EXCEL VBA/SELEIUM"单击按钮"<>"找不到元素"错误



我在尝试点击";下载按钮";我能够浏览页面。但当点击.xlsx下载按钮(按钮-1127(时,它找不到元素。有更好的方法吗??对不起,我的VBA编码太粗糙了。。我唯一能想到的是它,因为它需要在可点击之前悬停。在Chrome inspect中,我确实看到了btn按下并悬停的类更改。我试过xpath,结果也一样。

元素在iframe 中

<iframe id="uxtabiframe-1061-iframeEl">

Xpath:

//*[@id="button-1127"]

要素:

<a class="x-btn x-unselectable x-box-item x-toolbar-item uft-id-gridexportexcel x-btn-gridtoolbar-toolbar-small" hidefocus="on" unselectable="on" role="button" aria-hidden="false" aria-disabled="false" id="button-1127" tabindex="10910" data-componentid="button-1127" style="left: 2794px; margin: 0px; top: 3px;"><span id="button-1127-btnWrap" data-ref="btnWrap" role="presentation" unselectable="on" style="" class="x-btn-wrap x-btn-wrap-gridtoolbar-toolbar-small "><span id="button-1127-btnEl" data-ref="btnEl" role="presentation" unselectable="on" style="" class="x-btn-button x-btn-button-gridtoolbar-toolbar-small  x-btn-no-text x-btn-icon x-btn-icon-left x-btn-button-center "><span id="button-1127-btnIconEl" data-ref="btnIconEl" role="presentation" unselectable="on" class="x-btn-icon-el x-btn-icon-el-gridtoolbar-toolbar-small exportExcel " style=""></span><span id="button-1127-btnInnerEl" data-ref="btnInnerEl" unselectable="on" class="x-btn-inner x-btn-inner-gridtoolbar-toolbar-small">&nbsp;</span></span></span></a>

代码:'

Set d = New ChromeDriver
With d

.SetPreference "download.default_directory", DOWNLOAD_DIRECTORY
.SetPreference "download.directory_upgrade", True 'safeguard
.SetPreference "download.prompt_for_download", False 'safeguard
.Get URL
.FindElementById("textfield-1034-inputEl").Click
.SendKeys ("*******")
Application.Wait (Now + TimeValue("00:00:1"))
.FindElementById("textfield-1035-labelEl").Click
.SendKeys ("******")
Application.Wait (Now + TimeValue("00:00:1"))
.FindElementById("button-1036").Click
Application.Wait (Now + TimeValue("00:00:5"))
.FindElementById("tab-1064-btnEl").Click
Application.Wait (Now + TimeValue("00:00:10"))
.FindElementById("button-1127-btnEl").Click
Application.Wait (Now + TimeValue("00:00:10"))

d.Quit
End With   

`

我需要切换iframe以允许查看元素。

示例:

.SwitchToFrame ("uxtabiframe-1061-iframeEl")
Application.Wait (Now + TimeValue("00:00:2"))
.FindElementById("button-1127").Click
Application.Wait (Now + TimeValue("00:00:5"))

相关内容

  • 没有找到相关文章

最新更新