C# Selenium Chrome automation, How to access an Htmlcollection using Selenium in visual studio

Asked

Viewed 61 times

1

Well personal, I’m trying to access an index of an HTML Collection by Selenium in visual studio, only that I’m not able to access, I’m using the classname to access a certain field, and seek its value.

on the island of Chrome is quiet:

document.getElementsByClassName('xxxx')[numero]

And the number goes from 0 to 7.

by Lenium I get to that:

nav.FindElement(By.ClassName("xxxx"));

I’m using C# for automation.

1 answer

1


Singular takes an element:

nav.FindElement(By.ClassName("xxxx"));

Plural handle all available:

nav.FindElements(By.ClassName("xxxx"));
  • It worked, now accessing ok, one more question. when I try to grab the value of the field in question with this command: string value = Nav.Findelements(By.Classname("x-combo-list-item")[0]. Text; it is taking too long to perform the search. and brings me an Iseachcontext list with the index total that has my collection. how do I make it fetch only the value of the index in question

  • @Romssnes may be taking too long because the page hasn’t loaded yet. I use Selenium with C# for a long time and never had problem of slowness, only when the websites accessed are slow to load the first elements or when the site is very badly done, but overall is fast.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.