Automate Web Elements Without ID's
How to automate web pages with web elements without id's using excel macros?
Steps:
Step 1: Open VBA editor on a new excel file and create a new module.
Step 2: Copy below code in the vba module.
Sub webElementsWithoutID's()
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
strURL = "https://www.automationandagile.com/p/sample-form.html"
IE.Navigate strURL
Do While IE.Busy
Application.Wait DateAdd("s", 2, Now)
Loop
Set doc = IE.Document
doc.getElementsByName("fname")(0).Value = "test1234"
doc.getElementsByName("lname")(0).Value = "test1234"
doc.getElementsByName("gender")(1).Click
doc.getElementsByName("hoobies")(1).Click
doc.getElementsByName("hoobies")(3).Click
doc.getElementsByClassName("ddl")(0).Value = "Service"
doc.getElementsByName("day")(0).Value = "12"
doc.getElementsByClassName("ddl")(2).Value = "2"
doc.getElementsByName("day")(1).Value = "1925"
doc.getElementsByClassName("btn")(0).Click
End Sub
Step 3: Run the module and enjoy :)