Issue
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
Solution
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:
- Is edge installed?
- Do you have the latest MicrosoftEdgeDriver server.?
- 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.
Answered By - Adelin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.