Reputation: 35
I got a very weird problem when trying out webdriverjs on my windows machine and would like your help or suggestion on this one. I follow the instruction online, first npm install selenium-webdriver, then download chromedriver and configure its path. Before proceed to testing I double check the installation, chrome and firefox are working properly and when running "chromedriver" on cmd it also works correctly "Starting ChromeDriver 2.14.313457 on port 9515 Only local connections are allowed." So i assume the system setup is correct. Then I tried the first simple example using js. Below is my code:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
driver.get('http://www.google.com/ncr');
driver.sleep(10000);
driver.quit();
This works perfectly fine with firefox,and firefox is opened and directed to the google page. However, when i switch to the second example by using chrome, the chrome never opened and no error messages showed, it just stuck there. Here is the second example I used, the only difference from the first one is changing firefox to chrome
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.google.com/ncr');
driver.sleep(10000);
driver.quit();
I dont know why chrome is not opened by webdriver, i searched the internet for some answers but didn't find any.
Here comes the more weird part. I changed my code to build a firefox-driver first, and then build the chrome-driver, code shown below
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
var driver_2 = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver_2.sleep(10000);
driver_2.quit();
In this way, both firefox and chrome is opened. So my question is "why chrome is not opened unless i build a firefox before it"??? Please give me some suggestions on this, or is that some setup in my computer is wrong? Thanks for all your help!!!
Upvotes: 1
Views: 2432
Reputation: 26
The setup is correct, but the way you using chrome-driver is incorrect. After running chrome-driver, it will show you the port it runs on, by default it is port 9515. Then in your code you should use "usingServer",
var driver = new webdriver.Builder().
usingServer('http://localhost:9515').
withCapabilities(webdriver.Capabilities.chrome()).
build();
to access chromedriver. That way chrome-driver can work correctly.
Upvotes: 1