Selenium + Node
Introduction to Selenium Webdriver Introduction to Node.js Installation and Environment set up NPM – Package Manage for Node.js Directory layout of Selenium Webdriver Node.js package Chrome Chrome with options Chrome in Mobile Emulation IE Firefox Element identification methodsAssertions in Selenium in Node.js Interacting with elements in Selenium in Node.js Basic Browser window automation Sending keys in Selenium in Node.js Synchronization in Selenium Check if Element exists Working with Tables using Selenium Performing advanced actions using Selenium in Node.js Executing JavaScript in Selenium in Node.js Working with multiple Browser Windows or tabs Working with multiple frames Handling alerts Common exceptions in Selenium Taking a screenshot in selenium Mocha – Unit testing framework Selenium gridElement identification in Selenium in node
We can identify the web elements using below Element locators in Node.js- className
- tagName
- name
- id
- xpath
- css
- linkText
- partialLinkText
driver.findElement(By.className(‘myclassName’)).sendKeys(‘watson’);
driver.findElement(By.tagName(‘input’)).sendKeys(‘watson’);
driver.findElement(By.name(‘fname’)).sendKeys(‘watson’);
driver.findElement(By.id(‘myid’)).sendKeys(‘watson’);
driver.findElement(By.xpath(‘//input[@name=’fname’]’)).sendKeys(‘watson’);
driver.findElement(By.css(‘input[name=’fname’]’)).sendKeys(‘watson’);
driver.findElement(By.linkText(‘Home’)).click();
driver.findElement(By.partialLintText(‘me’)).click();
findElements method returns array of elements. This method returns all elements matching given locator. Here is an example on findElements method
var webdriver = require(‘selenium-webdriver’);
//create shortcuts for By and until classes
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser(‘chrome’)
.build();
driver.get(‘https://www.softpost.org’);
var webElements = driver.findElements(By.partialLinkText(“torial”));
webElements.then(function (elements) {
//Work on each element
for (var i=0; i < elements.length; i++){
elements[i].getText().then(function(txt){
console.log(txt + “
”);
});
}
});
//close the browser
driver.close();
driver.quit();
Web development and Automation testing
solutions delivered!!