感谢您的帮助我一直在挠头,并在谷歌上搜索所有文章。基本上,我想提取REQ ID并将其放在Excel表格中。REQ ID总是以REQ和6个零开头。无论如何,我可以使用Xpath查找文本来做到这一点吗?不幸的是,下面的代码导致了一个空值,因为许多元素共享相同的";类";。理想情况下,它将尝试找到文本";REQ000000";在页面上。如果找到,它会给我标签的内容,或者选择整个REQ00000012345。
<p _ngcontent-tme-c63="" class="headline-item__description font-weight-light text-secondary ng-star-inserted"> REQ00000012345 <!----></p>
Sub GetReqID()
Sheets("Sheet1").Select
Dim Applicant, act As String
Dim answer, answer1, i As Integer
Dim d As WebDriver
Set d = New ChromeDriver
Dim keys As New Selenium.keys
Dim url As String
url = "https://url.com"
With d
.Start "Chrome"
.Get url
.Window.Maximize
'Wait 3 seconds
Application.Wait (Now + TimeValue("0:00:03"))
'Login
d.FindElementById("user_lg").SendKeys "username"
d.FindElementById("login_user_pwd").SendKeys "password"
d.FindElementById("login-btn").Click
'After logging in present dialog
answer = MsgBox("Get REQ# for " & Applicant, vbQuestion + vbYesNo + vbDefaultButton1, "Procced")
If answer = vbYes Then
Dim REQ As String
REQ = d.FindElementByXPath("//*[contains(@class, '" + "headline-item__description font-weight-light text-secondary ng-star-inserted" + "')]").Text
MsgBox REQ
End If
End With
answer1 = MsgBox("Have you clicked Submit for " & Applicant, vbQuestion + vbYesNo + vbDefaultButton1, "Procced")
If answer1 = vbYes Then
d.Quit
Else
MsgBox "Close the file to end session", vbCritical, "Not Done?"
End If
End Sub
我处理这个问题的方法是将所有标记提取到Excel工作表中。子程序在找到REQ000000时停止。