Why does adding toString() to getText() of a WebElement give a different output when not adding it while printing the WebElement texts?


This Content is from Stack Overflow. Question asked by user2044296

I wrote a code to print all the texts(country list) present with the WebElement (div) list, using getText() without adding toString() to it, it prints some of the initial countries in the list not all, but if toString() is added to getText() then all the countries are printed, why is there a difference in the output, without using toString() prints some initial countries but why not all?

for(WebElement w : fromCountriesList)

The source code snippet can be seen in the attachmententer image description here


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?