Skip to content
Advertisement

How to filter Selenium results setting a query limit?

I managed to get the data I wanted with selenium, but now I only need the first 17 data that it gives me, I need to make a kind of filter with this data, because I’m going to use conditions on top of them to use in another code.

JavaScript

My result is below

JavaScript

As you can see he gave me several returns but I only need the first 17 from top to bottom in order, I don’t need these names below nor this information that is in front of them. How can I do that?

Advertisement

Answer

To extract the first 17 datas you can use List Slicing and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    JavaScript
  • Using XPATH:

    JavaScript
  • Console Output:

    JavaScript
Advertisement