Selenium webdriver click google search

后端 未结 7 1035
情话喂你
情话喂你 2021-02-01 07:06

I\'m searching text \"Cheese!\" on google homepage and unsure how can I can click on the searched links after pressing the search button. For example I wanted to click the third

7条回答
  •  终归单人心
    2021-02-01 07:41

    public class GoogleSearch {
    
        public static void main(String[] args) {
    
            WebDriver driver=new FirefoxDriver();
            driver.get("http://www.google.com");
            driver.findElement(By.xpath("//input[@type='text']")).sendKeys("Cheese");   
            driver.findElement(By.xpath("//button[@name='btnG']")).click();
            driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 
            driver.findElement(By.xpath("(//h3[@class='r']/a)[3]")).click();
            driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 
        }
    }
    

提交回复
热议问题