I want to perform repetitive processing

grudadq2

New Member
Joined
Oct 18, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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.


--

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
 

Attachments

  • Image 1040.jpg
    Image 1040.jpg
    180.4 KB · Views: 6
  • Image 1041.jpg
    Image 1041.jpg
    248.5 KB · Views: 5

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top