selenium webdriver

How to use Selenium webdriver with Javascript on Mac

Spread the love

I am managing many accounts CMS, Google account and ETC. My new project is making automated account creation system so that I can spend less time to do boring works.

You can imagine that type just name and email address in the form, it will open browser and open chrome browser and go google admin account page and click create new and adding the typed information accordingly. Then go to CMS account page and create an account in the same way. Wonderful, I can save couple minutes or even an hour DAILY!

Selenium is browser automation solution.

To install this it need some preparation

First install Xcode. Open App store and search for Xcode, download and install.

apple download xcode

Another one is Homebrew. This makes installing software a lot easier. Open terminal and type this.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Homebrew, type this in terminal

Now, install node.

brew install node

install node using brew

Then Install chrome driver.

brew install chromedriver

install chrome driver

Make webdriver home folder and install selenium-webdriver.

mkdir webdriver
cd webdriver
npm init -y
npm install -S selenium-webdriver

Install selenium-webdriver

Note that there were error, without init npm. I got an error like ‘missing package.json warnings and errors off’. So I ran “npm init -y”. This will create package.json file.

Now everything is prepared.

Are you ready for launching new browser? Go!

Type node. And command like this order.

$ node
var webdriver = require('selenium-webdriver');

// Open Chrome Browser
var driver = new webdriver.Builder().forBrowser('chrome').build();
OR
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();

// Open google.com
driver.get('http://www.google.com');

Then browser opened and open google home page.
Launching selenium webdriver

Now create js file which includes all the commands like this. I have created open_browser.js file using below commands.
Open browser command selenium

And Run js file.

node open_browser.js

open chrome browser using selenium

Working good. I will post how to login to google account for next step.

Will this makes me lazy? Not sure!

Facebook Comments

Published by

Titus Choi

I love technology. Working for information technology. Interested in AVR technology. Playing with RC stuff.