E
E
Eugene2018-09-08 16:09:09
Node.js
Eugene, 2018-09-08 16:09:09

How to fix phantomjs error in node.js?

When trying to run a script that uses selenium webdriver and phantomjs, it gives the following error:

TypeError: webdriver.Capabilities.phantomjs is not a function
at Object. (C:\Users\Administrator\WebstormProjects\project\test.js:8:46)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal /modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node. js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

Installed phantomjs and selenium-webdriver via npm
Code:
const webdriver = require('selenium-webdriver');
const by = webdriver.By;

var browser = new webdriver
    .Builder()
    .withCapabilities(webdriver.Capabilities.phantomjs())
    .build();

browser.manage().window().setSize(800, 600);
browser.get('https://instagram.com/login');
browser.sleep(20000);
browser.findElement(by.xpath('//*[@id="root"]/div/div[2]/div[1]/form/div[1]/label/input')).sendKeys('login');
browser.findElement(by.xpath('//*[@id="root"]/div/div[2]/div[1]/div/form/div[2]/label/input')).sendKeys('password');
browser.findElement(by.xpath('//*[@id="root"]/div/div[2]/div[1]/div/form/div[4]/button[1]/span/span')).click();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qq1, 2018-09-08
@you_are_enot

What version of selenium-webdriver do you have? By default, 4.0.0-alpha.1 is currently installed.
On version 3.6.0, your code worksnpm i --save [email protected]3.6.0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question