I am developing a chrome extension which has content scripts. I am starting
the extension when I start chromedriver like this:
chromeOptions.addArguments("--load-extension=" + <path to my extension>);
This is all working sweetly, except for one issue ...
When I execute a script via webdriver, it is looking for the function in my
extension's content script, not the page under test's main frame.
WebElement tabIFrame = webdriver.findElement(By.xpath("//iframe[contains(@id, 'ext-comp-')]"));
webdriver.switchTo().frame(tabIFrame);
((JavascriptExecutor)webdriver).executeScript("navigateToUrl('https://...', 'LIST_VIEW','newCase');");
I know this because I have added the function being invoked to my content
script and the console.error is appearing in the console:
navigateToUrl = function(a, b, c) {
console.error("!!!!! navigateToUrl: " + a + "," + b + "," + c);
}
console > !!!!! navigateToUrl: https://eu2.salesforce.com/006b0000008jBhe,LIST_VIEW,newCase
If I don't add it to the content script, I get a "navigateToUrl is not defined"
error, but it works fine if I remove my extension when starting chromedriver:
WebDriverException: unknown error: navigateToUrl is not defined
I have tried this under both Mac and Windows 8 with the same outcomes. One
consideration here is that the script to be executed is in an iframe (which I
switch to first).
Steps to reproduce (if relevant, you MUST provide a simplified html page or
link to public site):
1. Run chromedriver with an extension.
2. Attempt to execute a script that invokes a function on the main page via
JavascriptExecutor.executeScript.
Expected behaviour:
- Script should execute in the main page's isolated world (or context).
Actual behaviour:
- Chromedriver executes the script in the extension's isolated world and does
not find javascript functions defined in the main page.
Original issue reported on code.google.com by p...@noffke.co.uk on 14 Aug 2014 at 8:35
Original issue reported on code.google.com by
p...@noffke.co.uk
on 14 Aug 2014 at 8:35Attachments: