Javascript Selenium Webdriver with Edge TypeError: Cannot read property 'start' of null
Asked Answered
I

3

5

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
Insignificance answered 2/2, 2018 at 7:41 Comment(6)
why 'MicrosoftEdge' and not 'edge'? Also, is the edge webdriver in the PATH?Hollander
I first tried 'edge' but this didnt work either. Yeah the edge webdriver is in PATH defined.Insignificance
With 'edge' is the same error?Hollander
Its the same type of error but an different error. (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)? How do I use usingServer(url)?Insignificance
Do you have latest selenium?Hollander
Yes, its the newest version.I installed it via npm install selenium-webdriverInsignificance
H
6

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

The main topic:

Do not know how to build driver: edge; did you forget to call usingServer(url)?

This can happen due to many reasons:

  1. Is edge installed?
  2. Do you have the latest MicrosoftEdgeDriver server.?
  3. Is 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.

Hollander answered 2/2, 2018 at 8:45 Comment(0)
O
1

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();
        }
    })();
Obscenity answered 14/5, 2019 at 7:19 Comment(0)
L
1

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();
Labrecque answered 3/1 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.