【发布时间】:2020-12-09 05:50:13
【问题描述】:
两个小时以来,我一直在尝试解决检查由 JavaScript 加载的网页上的复选框的问题。 这是所需页面的 html 页面 https://pastebin.com/Q1q28dR8
这是我到目前为止的代码
Private driver As New Selenium.ChromeDriver
Const sURL As String = "https://eservices.moj.gov.kw/"
Sub Test()
With driver
.Start "Chrome", sURL
.Get sURL
'#https://eservices.moj.gov.kw/#
'//*[@id="loginDiv"]/div/a[1]
.Wait 2000
''.FindElementByXPath("//*[@id='loginDiv']/div/a[1]").Click
.FindElementByClass("headerTabLeft").Click
.Wait 3000
.FindElementById("txtUserID").SendKeys "username"
.FindElementById("txtPWD").SendKeys "password"
.FindElementById("txtCaptcha").Click
.Wait 5000
.FindElementByXPath("//*[@id='frmLogin']/input[3]").Click
.Get sURL & "lawyerViews/lawOrders/"
.FindElementByLinkText("أوامر أداء جاهزة للدفع").Click
Dim dRows As Object
Set dRows = .FindElementsByCss("table.table-striped tbody tr")
'Debug.Print dRows.Count
.FindElementById("checkAll").Click
.Wait 3000
.FindElementById("checkAll").Click
.Wait 3000
Dim r As Long
For r = 1 To dRows.Count
Dim sRequestID As String
sRequestID = dRows.Item(r).FindElementsByTag("td")(2).Text
Dim x
x = Application.Match(Val(sRequestID), ActiveSheet.Columns(1), 0)
If Not IsError(x) Then
backP:
.Wait 2000
On Error Resume Next
On Error GoTo backP
.FindElementByXPath("//*[@id=""toBePaid[" & r - 1 & "]""]").Click
.Wait 2000
'.FindElementByXPath("//input[@type='checkbox'][@value='200512308']").Click
'.FindElementById("toBePaid[" & r - 1 & "]").WaitSelection True, 20000
'.Wait 2000
'.FindElementByCss("[type=checkbox][value='" & sRequestID & "']").Click
'.FindElementById("toBePaid[" & r - 1 & "]").Click
On Error GoTo 0
Debug.Print sRequestID & " Checked"
End If
Next r
Stop
End With
End Sub
第一个复选框只被选中,然后我收到一条错误消息,说“元素点击被拦截” 我尝试使用 id、xpath、css 并没有办法 有什么想法吗?
【问题讨论】:
-
那么,请问这条消息出现在哪一行?那个时候使用的 url 的价值是什么?
-
非常感谢我的导师。尝试在
If Not IsError(x) Then之后。我正在尝试从活动表中的 A 列匹配它后检查复选框。如果在工作表上找到数字,则选中与该数字相关的复选框。例如200512308.. 每个复选框没有特定的网址。我认为这个 javascript。 -
本页
.FindElementByLinkText("أوامر أداء جاهزة للدفع").Click。这是元素检查<a href="javascript:void(0);" onclick="dealSideLinkPage('/lawyerViews/lawOrders/readyToPay.jsp')">أوامر أداء جاهزة للدفع</a> -
返回的值是一个表
Set dRows = .FindElementsByCss("table.table-striped tbody tr"),在该表的行中,每一行都有自己的复选框,如<input type="checkbox" id="toBePaid[0]" name="toBePaid" value="200512308">。第一行为 0,第二行为 1,第三行为 2,以此类推。 -
你能匹配没有.click的元素吗?是否有 F8 等待?