Automate Chrome/Edge Browser


How to automate Chrome/Edge Browser using Excel macros?
Click Here For Video Explanation
Steps:

Step 1: Download Selenium VBA set up from here
Step 2: Start installation of Selenium VBA setup. (While installing make a note of the location where Selenium Basic gets installed)
Step 3: Go to the location where Selenium basic got installed
Step 4: Delete chromedriver.exe and edgedriver.exe
Step 5: Open Chrome/Edge browser and check version of the browser.
Step 5: For chrome browser go to Chrome Driver Download and download chrome driver corresponding to the Chrome browser Version.
For Edge browser go to Edge Driver Downloadand download edge driver corresponding to the Edge browser Version.

Step 7: Copy the downloaded chromedriver/edgedriver and paste at the location where Selenium basic was installed.
Step 8: Open a new excel file.
Step 9: Open Developer tab and insert a new module.
Step 10: On the top menu go to Tools/References.
Step 11: Scroll to find Selenium Type Library and select the option.
Step 12: Click Ok and close the reference window.
Step 13: Copy the code below in the module created.

Sub automation()

     Dim obj As New WebDriver
     obj.Start "edge","" '--For chrome browser replace edge with chrome
     obj.Get "https://www.automationandagile.com/p/sample-form.html"
     obj.FindElementByName("fname").sendKeys("test")
     obj.FindElementByName("lname").sendKeys("test")
     obj.FindElementByXpath("//*[@value='m']").click()
     obj.FindElementByXpath("//*[@value='Reading']").click()
     obj.FindElementByName("occupation").AsSelect.selectByText("Business")
     obj.FindElementByName("day").AsSelect.selectByText("31")
     obj.FindElementByName("month").AsSelect.selectByText("Dec")
     obj.FindElementByXpath("(//*[@name='day'])[2]").AsSelect.selectByText("1991")
     obj.FindElementById("btnSubmit").Click()


End Sub

Step 14: Run the module and enjoy :)