Skip to content

Instantly share code, notes, and snippets.

@sizovs
Forked from baltfilm/Application.java
Created August 29, 2019 09:26
Show Gist options
  • Save sizovs/a23f01c3d8bb937c9f84a2f7f1c84b8c to your computer and use it in GitHub Desktop.
Save sizovs/a23f01c3d8bb937c9f84a2f7f1c84b8c to your computer and use it in GitHub Desktop.
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
class Application {
public static void main(String[] args) {
ChromeDriver driver = new ChromeDriver();
driver.get("https://google.com");
WebElement query = driver.findElement(By.name("q"));
query.sendKeys("car rental riga");
WebElement searchButton = driver.findElement(By.cssSelector("input[value='Google Search']"));
searchButton.submit();
int pageNumber = 2;
final int LAST_PAGE = 15;
while (pageNumber < LAST_PAGE){
if (pageNumber == LAST_PAGE)
break;
WebElement page = driver.findElementByLinkText("" + pageNumber);
page.click();
List<WebElement> Titles = driver.findElementsByTagName("h3");
for (WebElement title : Titles) {
String t = title.getText();
System.out.println(t);
}
System.out.println("==========Titles of Next page=========");
pageNumber ++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment