Read/Write .xls and .xlsx with one set of code using POI - WorkbookFactory
we have to use:
For handling .xls files, we use HSSF (Horrible SpreadSheet Format) related POI classes.
For handling .xlsx files, we use XSSF (XML SpreadSheet Format) related POI classes.
On this post, how we can perform excel operations with one set code for both excel formats .xls and .xlsx.
For this we have a class provided from Apache POI WorkbookFactory, which auto detects appropriate kind of Workbook (HSSFWorkbook or XSSFWorkbook) depending on the excel formats .xls or .xlsx.
Let's jump to the code implementation
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Internet Explorer IE11 - F12 (debugging) not working
here is the fix:
Download and install the below respective patch, restart and click on F12 to get the html content.
For 32bit system:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=45134
For 64bit system:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=45154
Hope this helps!
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Download files in Chrome browser using selenium WebDriver
Find below code to download files in Chrome browser:
public class DownloadXL {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
String downloadFilepath = "c:/download";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(cap);
driver.get("http://www.seleniumhq.org/download/");
driver.findElement(By.linkText("32 bit Windows IE")).click();
}
}
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Execute JavaScript in selenium to perform operations on HTML elements
Now let's see how we can perform actions on different web elements like
textbox - how we can enter text
Button - click
How to get attribute of a html element...
For input buttons
//js.executeScript("return document.getElementsByName('commit')[0].click();")
//or
//element = (WebElement) js.executeScript("return document.getElementsByName('commit')[0];");
//((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
//or
//element.click();
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Execute javaScript (locators) in selenium to identify HTML element
JavaScript has it's own locators to identify web elements:
getElementById - Returns single element that matches the ID.
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Play with scroll bars on a page in selenium and javaScript
Selenium do not have it's own methods to perform this action, so we can use javascript to play on scroll lbars.
Let's see some of the ways:
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
All about JavaScriptExecutor in Selenium
Sometimes we observe web controls doesn't react well to selenium commands, there we can directly use / execute javascript commands using webdriver,
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
ways to drag n drop elements using selenium
Some examples:
Can customize menu bar items by drag child elements on parent element.
Drag and drop files/folders in some hierarchy manner.
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
which one to use? driver.close() / .quit()
Depending on scenarios, if single or multiple browsers are opened, we can close or quit browser.
let's see the usage of close, quit and dispose methods.
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Selenium v2.47.0 - features added

Download link:
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Selenium with Autoit (no installation) for win UIs
There are situations in selenium automation, we get window dialog or we can say non browser related dialog which can not be automated with selenium. e.g Upload a file, download a file etc..
We will see how we can integrate Autoit with Selenium without installing Autoit.
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Selenium HTML result reporting using ExtentReports 2.X
While browsing different ways of reporting, got web links of ExtentReports, most of the links talk about the version 1.x,
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Connect to DataBase in Java and Selenium Implementation
refer MySQL Basics
To automate database testing, we will use selenium with java language.
JDBC (Java DataBase Connectivity) is an API (using Java language) to connect and play with database with SQL queries.
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Firefox profile and preferences in selenium
Firefox profile contains information like your homepage, bookmarks, browser settings, history, saved passwords.
Profile is basically a specific folder stored locally in your hard drive other than your firefox installation folder.
We will see how we can set Firefox profile manually and then call in code or directly we can set the Firefox profile in code itself.
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
Selenium - ways to handle dropdown menus
Each item in the menu bar is a link corresponds to another page.
Menu bar have root items and in each root items we have one or more sub menus/items.
Actions on Root elements of a menu bar can be done as normal links, but sub elements are ( are hidden) only visible if we mouse hover to their corresponding root element,
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
selenium implicit + Explicit + fluent waits
Loading depends on different criteria like internet bandwidth, technology used in the application, server capacity, no of users accessing the browser app etc...
While executing tests in different machines/environments, we need to make sure our script or code should wait till the elements load/present on the web page to perform some action upon them...
Selenium provides different ways to wait for an element on web page...
let's see them one by one -
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
TestNG @Test attributes - threadPoolSize, invocationCount, timeOut
public class InvocationCnt { @Test(invocationCount=5) public void test1() throws InterruptedException { System.out.println("Thread ID: "+Thread.currentThread().getId()); } }
OutPut:
Thread ID: 1
Thread ID: 1
Thread ID: 1
Thread ID: 1
Thread ID: 1
above method ran 5 times, a single thread will be assigned to run the method one by one..
Now let's see with threadPoolSize implementation
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
TestNG @Test attributes - AlwaysRun
let's see the code implementation
public class AlwaysRun { WebDriver driver; @Test public void test1() { driver = new FirefoxDriver(); driver.get("http:\\qavalidation.com"); Assert.assertTrue(driver.getTitle().contains("Testing")); } @Test(dependsOnMethods = {"test1"}, alwaysRun=true) public void test2() { driver.findElement(By.linkText("Selenium Tutorial!")).click(); } }
Observe the output, even though test1 did not run, test2 executed.
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
TestNG @Test attributes - dependOnMethods
if a particular test is run fine, then execute this test or else skip the test execution...
Basically we are creating inter dependencies in test execution.
Examples
Launch browser with URL, verify if title matches, then login
In Gmail, if login successful, then verify if Inbox link present or not
If report generated, then print the report
Let's see the code implementation
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!
TestNG @Test attributes - enabled property
for this TestNG provides enabled property to skip the execution of methods...
enabled = false (skip the method run)
enabled = true (execute method), it's by default set to true,
NOTE: if we do not mention enabled property, it's set to true
Let's see the code implementation
This article is based on my learning or working experience, please leave comments if anything needs to be added or updated, Thanks!