Saswat Saswat - 1 year ago 147
Node.js Question

How to use phantomJS to open a sitelink using selenium webdriver?

I have installed selenium webdriver via npm by the following method:

C:\xampp\htdocs\testPhantomJS>npm install selenium-webdriver

Then I have put the phantomjs scripts(codes) in the same folder location.

My folder now looks like the image given below:

enter image description here


I am trying to use headless Webkit of PhantomJS to open through Selenium Webdriver but when I execute the following code system, some error occurs.

Script: test.js

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
var baseUrl = '';

driver.wait(until.titleIs('webdriver - Google Search'), 1000);

I am running the code through command prompt using node.js

C:\xampp\htdocs\testPhantomJS\node_modules\selenium-webdriver >node test.js

After running this, I am getting some error, which is stated below:


enter image description here

Answer Source

You have to require the By tool seperately.

var By = require('selenium-webdriver').By;

Or you can use it like this: webdriver.By.func()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download