Recently Selenium released their major version as Selenium 4 and announced there will not be any support further for PhantomJS from Selenium4 onwards. Is that mean Selenium no longer supports for headless automation or is there any way to execute the tests in headless mode in Selenium version 4? Appreciate code examples.
In Selenium 4, native support has been removed for PhantomJS. Still, the users who run the scripts on headless mode using PhantomJS, can use Chrome or Firefox in headless mode as shown below.
const chrome = require('../chrome');
const firefox = require('../firefox');
const {Builder, By, Key, until} = require('..');
const width = 640;
const height = 480;
let driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(
new chrome.Options().headless().windowSize({width, height}))
.setFirefoxOptions(
new firefox.Options().headless().windowSize({width, height}))
.build();
driver.get('http://www.google.com/ncr')
.then(_ =>
driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN))
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
.then(
_ => driver.quit(),
e => driver.quit().then(() => { throw e; }));
To learn more about Selenium 4 changes please refer Selenium 4 (alpha) is Released: What’s New?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With