Created
September 9, 2019 06:18
-
-
Save baltfilm/a108980c8623e5933b022362e6a94ae9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
while (!driver.findElementsById("pnnext").isEmpty()) { | |
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