MGames
MGames

Reputation: 1181

Selenium WebDriver: Chrome not working after deployment on my Mac

To install the chromedriver and selenium-webdriver I used

    npm install chromedriver --save
    npm install selenium-webdriver --save

After running this code, the new chrome window opened with Google like it should:

var webDriver = require(‘selenium-webdriver’);
var chrome = require(‘selenium-webdriver/chrome’);
var path = require(‘chromedriver’).path;

var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);

var driver = new webdriver.Builder()
      .withCapabilities(webdriver.Capabilities.chrome())
       build();

driver.get(‘https://www.google.com’);

After deploying the application on my mac, here’s the error I get: Uncaught (in promise) Error: spawn ENOTDIR

-Any help would be appreciated, thank you!

Upvotes: 0

Views: 1323

Answers (1)

devilpreet
devilpreet

Reputation: 767

You need to follow the steps:

  1. Install selenium webdriver

    npm install selenium-webdriver --save

  2. Download the chrome webdriver
    ChromeDriver Home

  3. Install chromedriver

    npm install chromedriver --chromedriver_filepath=/Users/**/chromedriver_mac64.zip

  4. Javascript code

const {Builder, By, Key, until, Capabilities} = require('selenium-webdriver');  
    console.log(require('chromedriver'));  
    var chromeCapabilities = Capabilities.chrome();  
    var chromeOptions = {  
        'args': ['--test-type', '--start-maximized'],  
        'prefs': {  
          'download.default_directory': '/Users/**/app/output/'  
        }  
    };  
    chromeCapabilities.set('chromeOptions', chromeOptions);  
    
    (async function example() {  
      let driver = await new Builder().forBrowser('chrome')  
        .withCapabilities(chromeCapabilities)  
        .build();  
    
      console.log(await driver.getCapabilities());  
      try {  
        await driver.get('http://www.google.com');  
        await driver.wait(until.elementLocated(By.id('lst-ib')), 20000);  
      } finally {  
        await driver.quit();  
      }
    })(); 
 

Upvotes: 1

Related Questions