Selenium webdriver click google search

后端 未结 7 1034
情话喂你
情话喂你 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:57

    Based on quick inspection of google web, this would be CSS path to links in page list

    ol[id="rso"] h3[class="r"] a

    So you should do something like

    String path = "ol[id='rso'] h3[class='r'] a";
    driver.findElements(By.cssSelector(path)).get(2).click();
    

    However you could also use xpath which is not really recommended as a best practice and also JQuery locators but I am not sure if you can use them aynywhere else except inArquillian Graphene

提交回复
热议问题