Last active
May 22, 2023 08:19
-
-
Save akommareddi/e1ec2cf80372ab773bfe to your computer and use it in GitHub Desktop.
HowTo: Script Modify Headers for Google Chrome extension using Selenium
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
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
Actually, there's a way without extensions or proxys: