我正在尝试做这样一行点击 javascript 链接的操作
.FindElementById("ctl00_ContentPlaceHolder1_LinkButton4").WaitDisplayed(True, 3000).Click
这条线没有任何错误,但有时它不起作用..我说有时并不总是..有时工作,有时停止,我不知道原因
我必须重新启动代码才能启动新的机器人(驱动程序),在某些情况下我必须重新启动很多次,直到此链接起作用
这是这个 javascript 链接的 html 部分
<a id="ctl00_ContentPlaceHolder1_LinkButton4" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton4','')" style="display:inline-block;width:280px;text-decoration:none;height:22px;font-weight:bold;font-size:11pt;color:Maroon;border-width:1px;border-style:Dashed;border-color:#404040;background-color:#FFFFC0;vertical-align: middle; text-align: center; cursor: hand;">Some Text Removed For Privacy</a>
我怎样才能使这个链接工作......或者是否有解决方法使它工作..?
我试图解决这个问题,但我根本没有找到任何线索
这是响应式的 html 部分(我没有看到任何区别)
<a id="ctl00_ContentPlaceHolder1_LinkButton4" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton4','')" style="display:inline-block;width:280px;text-decoration:none;height:22px;font-weight:bold;font-size:11pt;color:Maroon;border-width:1px;border-style:Dashed;border-color:#404040;background-color:#FFFFC0;vertical-align: middle; text-align: center; cursor: hand;">Some Text Removed For Privacy/a>
这是执行此行后的错误快照
.ExecuteScript "javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton4'"
This is Network snapshot (may be useful) >> I see 302 (which I think there should be newer cache ..) so is there a way to clear the cache of the bot?
尝试在顶部执行以下操作
Const JS_WAIT_CLICKABLE = _
"var target = this, endtime = Date.now() + arguments[0];" & _
"(function check_clickable() {" & _
" var r = target.getBoundingClientRect(), x = r.left+r.width/2, y = r.top+r.height/2;" & _
" for (var e = document.elementFromPoint(x , y); e; e = e.parentElement)" & _
" if (e === target){ callback(target); return; }" & _
" if (Date.now() > endtime) { callback(target); return; }" & _
" setTimeout(check_clickable, 60);" & _
"})();" 'by @florentbr
Then
With .FindElementById("ctl00_ContentPlaceHolder1_LinkButton4")
.ExecuteAsyncScript(JS_WAIT_CLICKABLE, 10000) _
.Click
End With
您也可以尝试直接执行
.ExecuteScript "javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton4','');"
清除缓存并返回(因为按钮位于影子根目录中,您需要使用/deep/
组合器)
d.get "chrome://settings/clearBrowserData"
Dim button As Object
d.FindElementByCss("* /deep/ #clearBrowsingDataConfirm").Click
Set button = d.FindElementByCss("* /deep/ #clearBrowsingDataConfirm")
Const MAX_WAIT_SEC As Long = 15
Dim t As Date
t = Timer
Do
DoEvents
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop Until button Is Nothing
d.ExecuteScript "window.history.go(-2);"
或者潜在地,
d.GoBack
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)