The title says it all: I am wondering whether it is possible to interact with the Firefox console upon starting Firefox in headless mode.
More generally, I'd settle for some way of accessing it programmatically, in scripts.
What I've tried:
So far I've been playing with the Javascript bindings to Selenium without success:
Starting Firefox with the -devtools option from Selenium does opn the dev tools, but I then cannot send key combinations that will switch me to the actual console, or in fact interact from my .js
script with the open devtools window in any way.
Edit
In response to the first comment below: this answer does not seem to help. The console is not opened when I send CTRL+SHIFT+k
to the body
tag of google.com
:
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var firefox = require('selenium-webdriver/firefox');
var inpt = require('selenium-webdriver/lib/input');
var options = new firefox.Options();
var driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
(async function(){
await driver.get('https://google.com');
var bdy = await driver.findElement(By.id('gsr'));
await bdy.sendKeys(inpt.Key.CONTROL + inpt.Key.SHIFT + 'k');
})();
This opens the page (google.com
) and returns no errors, but there's no console anywhere.
For good measure: sending just inpt.Key.SHIFT + 'k'
does enter a capital 'K' in the Google search field, so I know the keys are referenced correctly.
Also, sending just 'k'
enters a small 'k' in the search field. It's only the three-key combo that does not work.
2nd edit:
I take it back: the newer answer does work, precisely as-is (I switched to Python from node
).