【发布时间】:2020-11-06 09:09:17
【问题描述】:
尝试自动化在线订单流程。订单规格完成后,您按下保存按钮。如果项目规格(高度)>1000mm,则会显示一个弹出窗口。我在自动单击它时遇到问题。它不在 iframe 中。
在下面的第二行代码中:
bot.FindElementById("ctl00_mainContent_ucOrderDetailBlind_btnSave").Click
“如果 >1000mm 条件为 TRUE,则单击“导致”弹出警告。它只有一个按钮 - 'OK'(编码为 nbsp;OKnbsp; )。手动单击允许自动进度转到下一页,但我需要帮助才能使编码自动执行此操作。目前,代码似乎已挂起,显示弹出窗口。 Debug表示下一条指令无法执行——显然是因为那个findElementById..Click找不到,因为进程卡住了。
我已经尝试了几种替代方案 - 请查看我尝试过的最有可能的代码。
If ThisWorkbook.Sheets("SquareSpace").Cells(r, "F").Value > 1000 Then ' The item is more than 1000mm high
bot.FindElementById("ctl00_mainContent_ucOrderDetailBlind_btnSave").Click
'Alternative 1
bot.FindElementByXPath("//input[@ID='popup_ok' and text()=' OK ']").Click
'Alternative 2
bot.SwitchToAlert.Accept
bot.Wait 1000
Alternative 3
bot.FindElementById("popup_ok").Click
Else ' for when the item is not more than 1000mm high
bot.FindElementById("ctl00_mainContent_ucOrderDetailBlind_btnSave").Click
bot.Wait 500
End If
'Then the next instruction of the form bot.FindElementById ......Click
为了清晰起见删除了一些内容的 HTML(文本和样式):
<div id="popup_container" class="ui-draggable" style="position: absolute; z-index: 99999; padding: 0px; margin: 0px; min-width: 604px; max-width: 604px; top: 0px; left: 647.5px;"><h1>Warning</h1>
<div id="popup_content" class="alert">
<div id="popup_message"><br>WARNING TEXT</div>
<div id="popup_panel"><input type="button" value=" OK " id="popup_ok"></div>
</div>
</div>
感谢任何建议。谢谢。
【问题讨论】:
标签: vba selenium xpath css-selectors popupwindow