Search code examples
vbaseleniumselenium-webdriverweb-scrapingtrello

How to count the elements from a class with VBA + SELENIUM in chrome?


I want to count the numbers of elements aiming to get all their names and store in an array.

The names are highlighted in this image

The names are store in "js-list list-wrapper" as shown in image

My code:

  Public Sub seleniumtutorial()
  Dim bot As New SeleniumWrapper.WebDriver
  Dim a As WebElement
  Dim b As WebElement
  Dim x() As Integer

  bot.Start "chrome", "https://trello.com/login"
  bot.get "/"

  bot.Type "name=user", "biaverly@id.uff.br"
  bot.Type "name=password", "xxxxxxx"
  bot.clickAndWait "id=login"
  bot.findElementByLinkText("Gestão de Pessoas").Click

I tried:

  Set a = bot.findElementsByClassName("board-canvas", 5).Count

and find elements by xpath,and id.


Solution

  • I got the xpath from a random element in the class "js-list list-wrapper" and it was: //*[@id="board"]/div[5].

    So i solved it using

     Dim titles As Object
     Set titles = 
     bot.findElementsByXPath("//[@id=""board""]/div")
     Dim ab As Long
     ab = titles.Count
     MsgBox ab