Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import java.util.List;
- public class Main
- {
- public static void main(String[] arguments)
- {
- // Specify the ChromeDriver binary
- System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
- // Create a ChromeDriver instance
- WebDriver driver = new ChromeDriver();
- // Visit Google
- driver.get("http://www.google.com");
- // Find the search field and enter the search term
- WebElement element = driver.findElement(By.name("q"));
- element.sendKeys("BullyWiiPlaza");
- element.submit();
- // Find the search results
- List<WebElement> searchResults = driver.findElements(By.cssSelector("#rso > div:nth-child(1) > div > div"));
- // Print the search results
- System.out.println("Search Results:");
- for (WebElement searchResult : searchResults)
- {
- WebElement searchResultURL = searchResult.findElement(By.cssSelector("div > div > div.r > a"));
- System.out.println(searchResultURL.getAttribute("href"));
- }
- // Quit the session
- driver.quit();
- }
- }
Add Comment
Please, Sign In to add comment