Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
Forked from akommareddi/Script Modify Headers
Created July 11, 2018 15:32
Show Gist options
  • Save liquidgenius/2d5043e572915098aaa884776efcb7d5 to your computer and use it in GitHub Desktop.
Save liquidgenius/2d5043e572915098aaa884776efcb7d5 to your computer and use it in GitHub Desktop.
HowTo: Script Modify Headers for Google Chrome extension using Selenium
System.setProperty("webdriver.chrome.driver",
"/opt/tools/selenium-2.45.0/chromedriver");
File addonpath = new File(
"/opt/tools/selenium-2.45.0/innpjfdalfhpcoinfnehdnbkglpmogdi.crx");
ChromeOptions options = new ChromeOptions();
options.addExtensions(addonpath);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(options);
driver.get("chrome-extension://innpjfdalfhpcoinfnehdnbkglpmogdi/options.html");
driver.navigate().refresh();
Thread.sleep(1000);
driver.findElement(By.xpath("//button[@tooltip='Add New']")).click();
WebElement actionElem = driver.findElement(By.name("action"));
Select select = new Select(actionElem);
select.selectByVisibleText("Add");
WebElement nameElem = driver.findElement(By.name("name"));
nameElem.sendKeys("some-key");
WebElement valueElem = driver.findElement(By.name("value"));
valueElem.sendKeys("some-value");
WebElement descElem = driver.findElement(By.name("description"));
descElem.sendKeys("some-desc");
driver.findElement(By.xpath("//button[@tooltip='Save']")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//button[@tooltip='Start Modifying Headers']")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//button[@tooltip='Enable']")).click();
Thread.sleep(2000);
driver.get("http://whatheaders.com");
Thread.sleep(30000); // Let the user actually see something!
driver.close();
driver.quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment