Issue
I am looking for below code to covert from internet Explorer to Edge browser, request for you help to sort the same.
Sub CHECK_STATUS()
Dim cell As Range
Dim IntExp As Object
Set IntExp = CreateObject("InternetExplorer.Application")
IntExp.Visible = False
For Each cell In Range("A2:A20000")
'Here A2 is cell Address where we have stored urls which we need to test.
If Left(cell.Value, 4) = "http" Then
' Goto web page
IntExp.navigate cell.Text
' Below loop will run until page is fully loaded
Do While IntExp.Busy Or IntExp.readyState <> 4
DoEvents
Loop
' Now use text which you want to search , error text which you want to compare etc.
Dim ieDoc As Object
Set ieDoc = IntExp.document
If ieDoc.getElementsByClassName("box-content").Length <> 0 Then
cell.Offset(, 1).Value = ieDoc.getElementsByClassName("box-content")(0).innerText
End If
End If
Next cell
IntExp.Quit
Set IntExp = Nothing
End Sub
Solution
You need to use SeleniumBasic to automate Edge in VBA. SeleniumBasic is a Selenium based browser automation framework for VB.Net, VBA and VBScript.
I agree with QHarr's comments, you can also follow the steps below to automate Edge browser with SeleniumBasic:
- Download the latest version of SeleniumBasic v2.0.9.0 from this link and install it.
- Download the corresponding version of Edge WebDriver from this link.
- Find the path of SeleniumBasic which is
C:\Users\%username%\AppData\Local\SeleniumBasic
in my computer (it might also be in this pathC:\Program Files\SeleniumBasic
), copy the Edge WebDrivermsedgedriver.exe
to this path. - Rename
msedgedriver.exe
toedgedriver.exe
. - Open Excel and write the VBA code.
- In the VBA code interface, click Tools > References, add Selenium Type Library reference and click OK to save.
- I write a simple VBA code to show how to automate Edge using SeleniumBasic. You can refer to it and change the code according to your own demands:
Public Sub Selenium()
For Each cell In Range("A2:A20000")
Dim bot As New WebDriver
If Left(cell.Value, 4) = "http" Then
bot.Start "edge", cell.Value
bot.Get "/"
If Not bot.FindElementsByClass("box-content") Is Nothing Then
cell.Offset(, 1).Value = bot.FindElementsByClass("box-content")(1).Text
End If
End If
bot.Wait 3000
bot.Quit
Next cell
End Sub
Answered By - Yu Zhou
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.