Keyword "Get Element Count" : results are different with 2 browsers

Hello.

I’m facing to a strange problem.
I want to count the number of element of a webpage, with this command :

${countBien}=    Get Element Count    //div[1]/inotr-bloc-annonce/div/div/div/h2/a/span[@class="type_bien"] 
Log    ${countBien}

But when I execute the test with Chrome browser, the result is 12 (and it’s false) and with the Firefox browser, the results is 2 (the good result).

How do you explain the difference ? Is there a solution to have the good result with Chrome ?

Thanks a lot.

John.

Hello,

I spent time to debug with a developer and we have found a clue :

This element “//div[1]/inotr-bloc-annonce/div/div/div/h2/a/span[@class=“type_bien”]” is a variable which is on a resource file.

So the code is :

On the resource file :
${blocAnnonceTypeBien} //div[@class="colonne_liste_annonces"]/inotr-bloc-annonce/div/div/div/h2/a/span[@class="type_bien"]

On the robot file :
${countBien}= Get Element Count ${blocAnnonceTypeBien} Log ${countBien}

The result is wrong.

But if I do :

${countBien}=    Get Element Count     //div[@class="colonne_liste_annonces"]/inotr-bloc-annonce/div/div/div/h2/a/span[@class="type_bien"]
Log    ${countBien}

The result is good !

Apparently, the variable is not executed at the good time.
Do you know why?

Thnaks !

John

Hi! You seem to mention two different selectors in your posts. Can you double-check that you indeed have the correct selector in the resource file and also that the Get Element Count gets the correct selector (you can try logging the selector before calling the keyword)?:

//div[1]/inotr-bloc-annonce/div/div/div/h2/a/span[@class="type_bien"]
//div[@class="colonne_liste_annonces"]/inotr-bloc-annonce/div/div/div/h2/a/span[@class="type_bien"]

Maybe worth checking if the variable is defined more than once, too, or if you accidentally override it somewhere. The logging should help with this.

Hello,

Thanks for your reply.
The 2 selectors are the same.

div[1]/… means that this is the first child.
div[@class=“colonne_liste_annonce”]/… too.

I have modified the “div” for checking and analysing where the issue could occur.

After many discussions, the dev team would add a specific attribute to target the element.
I hope this will resolve the problem :slight_smile:

1 Like