Skip to content

Instantly share code, notes, and snippets.

@DylanCh
Last active July 6, 2019 01:29
Show Gist options
  • Save DylanCh/03df8bd89ab2e0e4c6ec5662902d724f to your computer and use it in GitHub Desktop.
Save DylanCh/03df8bd89ab2e0e4c6ec5662902d724f to your computer and use it in GitHub Desktop.
// Step 1: download chromedriver version 70-72 into the project root folder
// Step 2: include this in pom.xml
/*
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
*/
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.*;
public class Main {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--whitelist-ip *");
chromeOptions.addArguments("--proxy-server='direct://'");
chromeOptions.addArguments("--proxy-bypass-list=*");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://google.com");
driver.findElement(By.cssSelector("input[title='Search']")).sendKeys("apple");
driver.findElement(By.cssSelector("input[title='Search']")).sendKeys(Keys.RETURN);
driver.findElement(By.xpath("//a[contains(text(), 'Wikipedia')]")).click();
Thread.sleep(3000);
driver.close();
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment