How to count no. of elements?

bytzu

Client
Регистрация
26.07.2013
Сообщения
15
Благодарностей
2
Баллы
3
Hello,


I scrape different pages each with different no of elements (div's with class='test' ) with the help of action designer. How can i know how many elements we have on each page?

Then i want to set a index and add each element to a list, but how can i know how many elements i have on each page ?

I give you an ex. in PHP maybe is more clear:

$index = 0;

//step 1

if($index < count($nr_of_elelments)){
//do something
$index++;
//go back to step 1
}else{
//do something else
}

I am interested on getting count($nr_of_elelments)

Anyone knows how to do this?
 

shade

Client
Регистрация
19.11.2010
Сообщения
580
Благодарностей
346
Баллы
63
Hello,


I scrape different pages each with different no of elements (div's with class='test' ) with the help of action designer. How can i know how many elements we have on each page?

Then i want to set a index and add each element to a list, but how can i know how many elements i have on each page ?

I give you an ex. in PHP maybe is more clear:

$index = 0;

//step 1

if($index < count($nr_of_elelments)){
//do something
$index++;
//go back to step 1
}else{
//do something else
}

I am interested on getting count($nr_of_elelments)

Anyone knows how to do this?
use C#:
JavaScript:
var col = instance.ActiveTab.FindElementsByAttribute("div", "class", "test", "text");
return col.Count;
 
  • Спасибо
Реакции: bytzu

bytzu

Client
Регистрация
26.07.2013
Сообщения
15
Благодарностей
2
Баллы
3
Thanks shade for your solution. It works fine. Looks like i will need to take a C# crash course

Out of curiosity does anybody knows another solution around it? There is another way getting the DOM and with regular expression putting the values into a list and then count list elements, but Shade's solution is the best until now.
 
  • Спасибо
Реакции: LightWood

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
His solutions are always the best. He's the man!
 
  • Спасибо
Реакции: shade

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)