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!