简体   繁体   中英

Example to use WebDriverJS (Selenium)

I have started learning WebDriverJs to test websites using Javascript as scripting language from url https://code.google.com/p/selenium/wiki/WebDriverJs but found some understanding issue at the beginning.

As per that page, I have to save chrome driver to some path. What is that path? How do that path link to sample below code?

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

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

driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
 return driver.getTitle().then(function(title) {
   return title === 'webdriver - Google Search';
 });
}, 1000);

driver.quit();

Installing from NPM

% npm install selenium-webdriver

Building from Source

 % git clone https://code.google.com/p/selenium/  
      % cd selenium   
     % ./go //javascript/node:selenium-webdriver

What is NPN and related codes? Kindly explain.

PS : I am basically from .Net background

Do I need to do any more setting to run the above code?

For example, any javascript files etc


Now I am able to install selenium-webdriver then I copied above javascript code in js file and tried to run it using node and received below error. Am I missing something?

尝试使用节点在JavaScript代码上方运行时出错

You seem to have a problem with the folder structure.

The How do I resolve "Cannot find module" error using Node.js? should help you resolve your issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM