Count the number of elements in a dropdown on a website

yussi1870

Board Regular
Joined
Mar 18, 2002
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I've tried a few options from scouring the web and I think my problem is I have Option Explicit set and I don't know which are variables to declare and what to declare them as. My code snippet is below. Basically I want to count how many elements are in the dropdown clicked here: .FindElementByXPath("//div[1]/*[name()='svg'][1]"). I then want to replace the 300 below with the count of elements. Any help is appreciated!

Dim iTotalScore As Integer
Dim iNameCount As Integer
Dim iNameCountTotal As Integer
Dim sName As String
Dim d As WebDriver
Set d = New ChromeDriver
With d
.Start "Chrome"
.Get "https://someurl.com"

For iNameCount = 1 To 300

.FindElementByXPath("//div[1]/*[name()='svg'][1]").Click
Application.Wait (Now + TimeValue("0:00:03"))
'do bunch of stuff

Next iNameCount
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this:
VBA Code:
    Dim ddOptions As WebElements, i As Long
    Set ddOptions = .FindElementsByXPath("//div[1]/*[name()='svg'][1]")
    For i = 1 To ddOptions.Count
        ddOptions(i).Click
    Next
 
Upvote 0
I got a type mismatch error on "set ddOptions." I declared it as webelements as you suggested. I put it within the "with d" area of the code. Should it have come prior to "with d"?
 
Upvote 0
ok, so it is inside the with d but I'm still getting that type mismatch error.
 
Upvote 0
FindElementsByXPath returns a WebElements object, so I don't understand why you're getting a type mismatch error.

Try declaring ddOptions as Object instead.
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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