I am trying to automate Edge using WebDriver.
I am trying to retrieve information from a relevant site (in this case, my Microsoft cdx account, and Message Center in Microsoft Management Center) and paste it into Excel.
I am attempting to retrieve information and paste it into Excel.
I am currently creating the following
<premise>
Excel
Sheet 1
Set start button for Excel macro
Sheet2
Enter the corresponding MC number in column A
Enter function in column B1 (https://admin.microsoft.com/Adminportal/Home?#/MessageCenter/:/messages/"&(A1))
Sheet3
Prepare a place to paste the acquired information
<Flow>
wsSheet1 = Sheet2
wsSheet2 = Sheet3
Autofill values in column B to blank rows in column A.
↓
※1 Open edge of specified profile
↓
Open URL for B1 of wsSheet1.
(Wait 3 seconds for browser to open)
↓
Get information on the corresponding xPath of the opened URL
↓
Close the edge
↓
Open Edge with specified profile
↓
※2 Open B2 URL for wsSheet1.
(Wait 3 seconds for browser to open)
↓
Get information on the corresponding xPath of the opened URL
↓
Close the edge
<Request>
I would like to repeat the above <flow>※ for all URLs in Sheet2.
(Currently, we specify B1※1 and B2※2 in Sheet2 and execute URLs one by one. In this way
I cannot execute for all URLs).
Could you please enlighten me on the iterative process?
Thank you in advance.
--
I am trying to retrieve information from a relevant site (in this case, my Microsoft cdx account, and Message Center in Microsoft Management Center) and paste it into Excel.
I am attempting to retrieve information and paste it into Excel.
I am currently creating the following
<premise>
Excel
Sheet 1
Set start button for Excel macro
Sheet2
Enter the corresponding MC number in column A
Enter function in column B1 (https://admin.microsoft.com/Adminportal/Home?#/MessageCenter/:/messages/"&(A1))
Sheet3
Prepare a place to paste the acquired information
<Flow>
wsSheet1 = Sheet2
wsSheet2 = Sheet3
Autofill values in column B to blank rows in column A.
↓
※1 Open edge of specified profile
↓
Open URL for B1 of wsSheet1.
(Wait 3 seconds for browser to open)
↓
Get information on the corresponding xPath of the opened URL
↓
Close the edge
↓
Open Edge with specified profile
↓
※2 Open B2 URL for wsSheet1.
(Wait 3 seconds for browser to open)
↓
Get information on the corresponding xPath of the opened URL
↓
Close the edge
<Request>
I would like to repeat the above <flow>※ for all URLs in Sheet2.
(Currently, we specify B1※1 and B2※2 in Sheet2 and execute URLs one by one. In this way
I cannot execute for all URLs).
Could you please enlighten me on the iterative process?
Thank you in advance.
--
VBA Code:
Dim Driver As New Selenium.EdgeDriver
Public Sub Test1018_3()
''MC427757 part is variable as it is displayed at "https://admin.microsoft.com/Adminportal/Home?#/MessageCenter/:/messages/MC427757".
'Put the original Excel1 or the corresponding MC number in a separate Excel Book2 (advance preparation).
'Create a URL with the corresponding MC number from Book2, and enter the function in column B.
Set wsSheet1 = ThisWorkbook.Worksheets("Sheet2")
Set wsSheet2 = ThisWorkbook.Worksheets("Sheet3")
'Autofill values in column B up to the blank line of values in column A
If Trim(wsSheet1.Range("A1")) <> "" Then
LastRow = wsSheet1.Range("A" & Rows.Count).End(xlUp).Row
wsSheet1.Range("B1").AutoFill Destination:=wsSheet1.Range("B1:B" & LastRow)
Else
End If
' Paste MC numbers read from Excel into :/messages/ or later and display in Edge browser
'First login requires new user registration, but after the second login, the existing profile will be automatically loaded and you will be able to log in (unless you clear your cache).
Dim str As String: str = "C:\\Users\\" & Environ("USERNAME") & "\\AppData\\Local\\Microsoft\\Edge\\User Data 15"
str = "--user-data-dir=" & str
Driver.SetCapability "ms:edgeOptions", "{""args"": [""" & str & """] }"
'Open the URL of column B 1 of wsSheet1, acquire the information, and paste it into Excel.
Driver.Get wsSheet1.Range("B1")
'Considering the slow popup, wait 3 seconds and paste into Excel
Application.Wait Now() + TimeValue("00:00:03")
'Extract information directly to EXCEL
'Service
wsSheet2.Range("A1") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[3]/div[2]/div").Text
'Title
wsSheet2.Range("B1") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[2]/div/h1/div").Text
'Message Summary
wsSheet2.Range("C1") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[7]/div[1]").Text
'affect
wsSheet2.Range("D1") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[5]/div").Text
'Quit the browser (WebDriver)
Driver.Close
'If multiple screens are open, close only the page currently displayed as the main page.
Set Driver = Nothing
'Open the Edge profile again
Dim str2 As String: str2 = "C:\\Users\\" & Environ("USERNAME") & "\\AppData\\Local\\Microsoft\\Edge\\User Data 15"
str2 = "--user-data-dir=" & str2
Driver.SetCapability "ms:edgeOptions", "{""args"": [""" & str2 & """] }"
'Open the URL of column B2 of wsSheet1, acquire the information, and paste it into Excel.
Driver.Get wsSheet1.Range("B2")
Application.Wait Now() + TimeValue("00:00:03")
'Service
wsSheet2.Range("A2") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[3]/div[2]/div").Text
'Title
wsSheet2.Range("B2") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[2]/div/h1/div").Text
'Message Summary
wsSheet2.Range("C2") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[7]/div[1]").Text
'affect
wsSheet2.Range("D2") = Driver.FindElementByXPath("/html/body/div[4]/div/div/div/div/div[3]/div/div[5]/div").Text
'Quit the browser (WebDriver)
Driver.Close
'If multiple screens are open, close only the page currently displayed as the main page.
Set Driver = Nothing
End Sub