I've been running an automation test on the website . When searching for a flight, I encountered an issue where I was unable to click on a particular flight. I initially tried using Xpath but it wasn't able to locate the element when it was at the bottom or middle of the page, prompting me to resort to the following solution:
JavascriptExecutor jsx2 = (JavascriptExecutor)driver;
jsx2.executeScript("window.scrollBy(0,750)", "");
driver.findElements(By.xpath("//a[text()='Select']")).get(15).click();
However, I am looking for a way to achieve this without having to scroll to a specific position since different screens may have different sizes.
I also attempted using CSS selectors but unfortunately, that did not yield success either.