Struggling to create selectors for identical buttons

Hello!

I’m working on scraping data from the results page of a travel website. Each flight listed on the results page has a button that will open an additional box underneath when clicked that contains the information I need to scrape.

The problem I’m having is that the button I need to click for each individual flight is identical for each flight listed. This is making it very difficult to create a unique selector that will allow me to click each button for every flight on the list.

The link below is an example of the type of page I’m working with. Each flight listed has a down arrow on the right side that can be clicked to reveal more information. How can I automate the clicking of each of these down arrows regardless of how many flights are listed?

(https://www.google.com/travel/flights/search?tfs=CBwQAhogEgoyMDIzLTA4LTA3KABqBwgBEgNEQ0FyBwgBEgNMR0FAAUgBcAGCAQsI____________AZgBAg&tfu=EgYIAxAAGAA)

1 Like

you have to use javascript since the selectors are very tricky as the website wants to discourage scraping.
heres the solution @tmcwade12

  1. write this into a textfile in your project folder name it e.g. “clickBtn.txt”
function(e, rowNumber){
document.querySelectorAll('[aria-label*="Flight details"]:not([hidden])')[rowNumber].click()
}
  1. use inject js activity, set target to body of the webpage
    image

  2. under script code property browse the text file you created above
    image

  3. under parameter put in the row number you want to click
    e.g. for first row type in this “0”
    for second row type “1”
    and so on…
    image

now if you run it , bot will click the row you want!

1 Like

I definitely would have never figured that one out on my own haha! Thank you very much I will give that a try right now.

Thanks again!

1 Like

no problem, let me know if it doesnt work and remember to mark the answer as solution if it works. thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.