Skip to content

Instantly share code, notes, and snippets.

@baltfilm
Created August 19, 2019 11:20
Show Gist options
  • Save baltfilm/432212b243adf8889f49db7d4de4c925 to your computer and use it in GitHub Desktop.
Save baltfilm/432212b243adf8889f49db7d4de4c925 to your computer and use it in GitHub Desktop.
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.sql.SQLOutput;
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();
System.out.println("========Titles from Page 1========");
List<WebElement> titles = driver.findElementsByTagName("h3");
for (WebElement title : titles) {
String t = title.getText();
System.out.println(t);
}
System.out.println("========Titles from Page 2========");
WebElement pageNumber2 = driver.findElementByLinkText("2");
pageNumber2.click();
List<WebElement> titlesOfPageTwo = driver.findElementsByTagName("h3");
for (WebElement title : titlesOfPageTwo) {
String t = title.getText();
System.out.println(t);
}
System.out.println("======Titles from Page 3========");
WebElement pageNumber3 = driver.findElementByLinkText("3");
pageNumber3.click();
List<WebElement> titlesOfPageThree = driver.findElementsByTagName("h3");
for (WebElement title : titlesOfPageThree) {
String t = title.getText();
System.out.println(t);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment