当我访问一个网站时,我点击一个链接。
除现有标签外,还会打开一个新标签。
我需要转到该标签并点击一个链接。
如何将新标签设置为活动的IE文档?
E.g。
我在网站下面打开。
“https://gradeup.co/how-to-fill-ssc-cpo-delhi-police-si-asi-online-application-form-i-5ed24332-b9e6-11e5-adce-a24a34b1a3cf”
点击“ssconline.nic.in”,会打开一个新标签页。现在我想点击“点击查看状态”链接。
代码会打开一个新标签,但无法点击“点击查看状态”。
Sub activatetab()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
URL = "https://gradeup.co/how-to-fill-ssc-cpo-delhi-police-si-asi-online-application-form-i-5ed24332-b9e6-11e5-adce-a24a34b1a3cf"
'Navigate to URL
IE.Navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
'Do While IE.ReadyState = 4: DoEvents: Loop 'Do While
'Do Until IE.ReadyState = 4: DoEvents: Loop 'Do Until
While IE.readyState <> 4 Or IE.Busy: DoEvents: Wend
'Click on step 1 :ssconline.nic.in
Dim myElement As Object
For Each myElement In IE.document.getelementsbyTagName("a")
'show the text content of 'tr' element being looked at
'Debug.Print myElement.outertext
If myElement.Outertext = "ssconline.nic.in" Then
myElement.Click
Exit For
End If
Next
'Click on step 2 :ssconline.nic.in
Dim oShell As Object
Dim oWin As Object
Dim i
i = 1
Set oShell = CreateObject("Shell.Application")
Set oWin = oShell.Windows()
'oWin.Item(i).Quit
Set IE2 = oWin.Item(i)
'Debug.Print IE2.Text
Dim myElement1 As Object
For Each myElement1 In IE2.document.getelementsbyTagName("a")
'show the text content of 'tr' element being looked at
Debug.Print myElement1.Outertext
If myElement1.Outertext = "Click to check status" Then
myElement1.Click
Exit For
End If
Next
End Sub