Reputation: 75
I'm trying to set up selenium-webdriver example using Javascript and Microsoft Edge. In any other browser this code below works. But Edge won't start. I tried to find a solution, but couldnt find anything that helped me... Maybe you can help.
const {Builder, By, Key, until} = require('selenium-webdriver');
(async function example() {
let driver = await new Builder().forBrowser('MicrosoftEdge').build();
try {
await driver.get('http://www.google.com/ncr');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
} finally {
await driver.quit();
}
})();
Its to easiest example from the webdriver's npm-page. https://www.npmjs.com/package/selenium-webdriver
I'm getting following error:
[Running] node "c:\Users\mr\Desktop\Selenium\SeleniumToJS\test.js"
(node:3700) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'start' of null
(node:3700) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[Done] exited with code=0 in 0.512 seconds
If I insert 'edge' instead of 'MicrosoftEdge' follwing returns:
[Running] node "c:\Users\mreinwald\Desktop\Selenium\SeleniumToJS\loginLogout.js"
(node:18112) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Do not know how to build driver: edge; did you forget to call usingServer(url)?
(node:18112) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[Done] exited with code=0 in 0.499 seconds
Upvotes: 5
Views: 8708
Reputation: 686
I was able to resolve this by importing "Browser" from selenium-webdriver:
const { Browser } = require("selenium-webdriver");
And then creating the edge driver with:
let driver = await new Builder().forBrowser(Browser.EDGE).build();
Upvotes: 1
Reputation: 111
The reason for the error is: webdriver is looking for Edge Service to start while creating edge session and it find it to null(as its not set).
The simple solution is create Edge service using Edge drive path.
const {Builder, By, Key, until} = require('selenium-webdriver');
const edge = require('selenium-webdriver/edge');
const edgedriver = require('edgedriver'); //If this driver is already on your system, then no need to install using npm.
(async function example() {
let service = await new edge.ServiceBuilder(edgedriver.path);
let driver = await new Builder.forBrowser('MicrosoftEdge').setEdgeService(service).build();
try {
await driver.get('http://www.google.com/ncr');
//...............
//...............
} finally {
await driver.quit();
}
})();
Upvotes: 1
Reputation: 8219
This line triggers the error:
new Builder().forBrowser('MicrosoftEdge').build();
Cannot read property 'start' of null
actually says: "I don't know what MicrosoftEdge is". Basically, in some instances, selenium expects one of: "firefox"
, "edge"
(instead of "MicrosoftEdge"
), "chrome"
, etc
Now
Do not know how to build driver: edge; did you forget to call usingServer(url)?
This can happen due to many reasons:
MicrosoftEdgeDriver
is on your PATH?If you answer yes to all of the above, then behind the scenes, while building, selenium didn't get the expected capabilities, and, for a last attempt, tries to connect to a remote webDriver
(that's why it says usingServer
)
As such, to solve this, you can try building the driver yourself, like this:
var edge = require('selenium-webdriver/edge');
var service = new edge.ServiceBuilder()
.setPort(55555)
.build();
var options = new edge.Options();
// configure browser options ...
var driver = edge.Driver.createSession(options, service);
And then you can continue with driver.get('http://www.google.com/ncr');
etc.
Upvotes: 6