Excel VBA to login to Wordpress using Selenium


Option Explicit

Private Sub Login()
    Dim driver As ChromeDriver
    Set driver = New ChromeDriver
    ' this works using either edge or Chrome
    Call driver.Start("edge", "https://wordpress.com/")
'    Call driver.Start("Chrome", "https://wordpress.com/")
    driver.get ("/wp-login.php")
    driver.Window.Maximize
    sbDelay (100000)
    driver.FindElementByClass("cookie-banner__accept-all-button").Click
    sbDelay (100000)
    driver.FindElementById("usernameOrEmail").Clear
    driver.FindElementById("usernameOrEmail").SendKeys "your username or email"
    sbDelay (100000)
    driver.FindElementByClass("button").Click 'Continue
    sbDelay (100000)
    driver.FindElementById("password").Clear
    driver.FindElementById("password").SendKeys "your password"
    sbDelay (100000)
    driver.FindElementByClass("button").Click 'Continue
    sbDelay (1000000)
    driver.Quit
End Sub

Sub sbDelay(delay As Long): Dim i As Long: For i = 1 To delay:  DoEvents: Next i: End Sub 'old skool delay
I used the VBA type library that Microsoft support https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ I used MS Edge - the Selenium version must match the version of edge that you have installed. Edge Version 110.0.1587.57 You will need to browse to the type library for your machine either 32 or 64 bit. Tools > References > Selenium Type Library (Selenium64.tlb)