如何在 google 网页的热门列表中 select 第二个?

How to select second one in trending list of google webpage?

package jdjjddk;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Htegsbn {

    public static void main(String[] args) {
        
        System.setProperty("webdriver.chrome.driver", "C:\Users\hp\Downloads\Compressed\Chromedriver.exe");
        WebDriver driver = new ChromeDriver(); 
        driver.get("https://www.google.com/");
        driver.findElement(By.xpath("//input[@title='Search']")).click();
        driver.findElement(By.xpath("//div[normalize-space()='Trending searches'][2]")).click();
        

    
    }

}

这是我写的代码,执行时停止显示趋势列表但不点击第二个。

Selenium 中你有 FindElements:

List<Element> elements = driver.findElements
(By.xpath("//div[normalize-space()='Trending searches']"));
elements[2].click();