Selenium Cheat Sheet

 Selenium Cheat Sheet


Driver Initialization

WebDriver driver = new ChromeDriver();
WebDriver driver = new FirefoxDriver();
WebDriver driver = new InternetExplorerDriver();
WebDriver driver = new EdgeDriver();
WebDriver driver = new SafariDriver();
WebDriver driver = new HtmlUnitDriver();

Web Driver Manager

WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();

WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();

WebDriverManager.edgedriver().setup();
WebDriver driver = new EdgeDriver();

WebDriverManager.safaridriver().setup();
WebDriver driver = new SafariDriver();

Advanced Browser Configuration

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--ignore-certificate-errors");
chromeOptions.addArguments("user-data-dir=Path");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--start-maximized", "--incognito","--disable-notifications" );
driver = new ChromeDriver(chromeOptions);

Desired Capabilities 

DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(“browserName”, “chrome”);
dc.setCapability(“browserVersion”, “96.0””);
dc.setCapability(“platformName”, “win10”);
WebDriver driver = new ChromeDriver(dc);

Element Locators

driver.findElement(By.id("Id Value"));
driver.findElement(By.name("Name Value"));
driver.findElement(By.className("Class Name Value"));
driver.findElement(By.linkText("Link text Value"));
driver.findElement(By.partialLinkText("Partial Text Constant Value"));
driver.findElement(By.tagName("Tag Name Value"));
driver.findElement(By.cssSelector("CSS Value"));
driver.findElement(By.xpath("Xpath Value"));
driver.findElement(with(By.tagName("input")).above(passwordField));
driver.findElement(with(By.tagName("input")).below(emailAddressField));
driver.findElement(with(By.tagName("button")).toLeftOf(submitButton));
driver.findElement(with(By.tagName("button")).toRightOf(submitButton));
driver.findElement(with(By.tagName("input")).near(emailAddressLabel));
driver.findElement(new ByAll(By.className("ElementClassName"), By.id("Element Id"), By.name("Element Name")))

Elements Operations

WebElement element = driver.FindElement(By.ElementLocator("Value of Element Locator"));
element.click();
element.sendKeys("Input Text");
element.clear();
element.submit();
element.getAttribute(“type”);
String innerText = element.getText();
boolean enabledstatus = element.isEnabled();
boolean displayedstatus = element.isDisplayed();
boolean selectedstatus = element.isSelected(); 

Operation on drop down 

Select select = new Select(element);
select.selectByIndex(Integer Index);
select.selectByVisibleText("Text");
select.SelectByValue("Value");
select.deselectAll();
select.deselectByIndex(Integer Index);
select.deselectByVisibleText("Text");
select.deselectByValue("Value");
WebElement selectedOptions = select.getOptions()

Browser Operations

String pageTitle = driver.getTitle();
String currentURL = getCurrentUrl();
String currentPageSource = driver.getPageSource();

Navigation history

driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
driver.manage().window().fullscreen();
driver.navigate().to("https://www.google.com/");
driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
driver.close();
driver.quit();

Handle Alert

Alert alert = driver.switchTo().alert();
alert.accept();
alert.dismiss();
alert.getText();
alert.sendKeys(“Input Data");

Handle Cookies

Cookie cookie = new Cookie(“cookieName”, “cookieValue”);
driver.manage().addCookie(cookie);
driver.manage().getCookies();
driver.manage().getCookieNamed(arg0);
driver.manage().deleteAllCookies();
driver.manage().deleteCookieNamed(arg0);

Handle frames

driver.switchTo().frame(int Frame Index);
driver.switchTo().frame("frameName");
WebElement element = driver.FindElement(By.ElementLocator("Value of Element Locator"));
driver.switchTo().frame(element);
driver.SwitchTo().defaultContent();

Screenshots Capture

TakesScreenshot screenshot =((TakesScreenshot)driver);
File srcFile= screenshot.getScreenshotAs(OutputType.FILE);
FileHandler.copy(srcFile, destFile);

Actions Class/Mouse Event

Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL);
action.keyUp(Keys.CONTROL);
action.clickAndHold(webElement).build().perform();
action.doubleClick(webElement).build().perform();
action.moveToElement(webElement).build().perform();
action.moveByOffset(xOffset,yOffset).build().perform();
action.dragAndDrop(sourceEle,targetEle).build().perform();
action.release().build().perform();

Manage Timeouts

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
welement = wait.until(Syntax: WebDriverWait wait = new
WebDriverWait(driver, timeout);
ExpectedConditions.elementToBeClickable(locator));
welement.click();
driver.manage().timeouts().pageLoadTimeout(30,TimeUnit.SECONDS);

Upload a File

WebElement element = driver.FindElement(By.ElementLocator("Value of Element Locator"));
element.sendKeys(filePath);

Window Handle

String handle=driver.getWindowHandle();
Set<String> handles = getWindowHandles();
driver.switchTo().window(handle);

Capture Width and Height of an Element

Point point = element.getLocation();
int elementWidth = element.getSize().getWidth();
int elementHeight = element.getSize().getHeight();

Window Handle

String handle=driver.getWindowHandle();
Set<String> handles = getWindowHandles();
driver.switchTo().window(handle);

Scroll Down or Up Web Page

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollBy(0,100)");
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
WebElement element = driver.FindElement(By.ElementLocator("Value of Element Locator"));
js. executeScript("arguments[0].scrollIntoView()", element);


Scroll Down Function with and without using Xpath

//Scrolling method with and without Xpath

public static void scrollbyElement(String Xpath, int pixel,WebDriver driver) throws Throwable {

JavascriptExecutor js = (JavascriptExecutor) driver; 

try {

if(path==null) {

js.executeScript("window.scrollBy(0,"+pixel+")"); //Scrolling the window by pixels vertically

sleep(2000);

}else {

WebElement element = driver.findElement( By.xpath(Xpath)); 

js.executeScript("arguments[0].scrollIntoView(true);", element);

sleep(2000);

}

}catch (Exception e) {

e.printStackTrace();

}

Random selection from Elements Function


//Random selection from element

public static void random_Selection(String elementsXpath, WebDriver driver) throws Throwable {

             int randomNumber=0;

List<WebElement> elements = driver.findElements(By.xpath(elementsXpath));   // Counting the number of filters in rule dropdown


if(elements.size()==1) {

driver.findElement(By.xpath(elementsXpath)).click();

}

else {

Random objGenerator = new Random();

randomNumber = objGenerator.nextInt(elements.size());

if(randomNumber==0)

{

randomNumber++;

}

//System.out.println(randomNumber);

driver.findElement(By.xpath(elementsXpath+"["+randomNumber+"]")).click();

sleep(1000);

}

}

Selenium Grid

Start hub
java-jar selenium-server- standalone-x.xx.x.jar-role hub 

Start node
java-jar selenium-server- standalone-x.xx.x.jar-role nodehub
http://localhost:4444/grid/register 

Server

 http://localhost:4444/grid/console

TestNG Annotations

@Test
@BeforeMethod
@AfterMethod
@BeforeTest
@AfterTest
@BeforeClass
@AfterClass
@Test(enabled = false)
@Test(enabled = true)
@Test(priority=2)
@Test(priority=5,dependsOnMethods={"method1","method2"})
@Test(dependsOnMethods = {"method1"}, alwaysRun=true)
@Test(groups = { "Group1", "Group2" })
@Parameters({"testparameter1", "testparameter2"})
@Listeners(packagename.ListenerClassName.class)
@Test (dataProvider = "getUserIDandPassword")
@Test (description = "Open Facebook Login Page", timeOut=35000)
@Test (invocationCount = 3, invocationTimeOut = 20000)
@Test (invocationCount = 3, skipFailedInvocations = true)
@Test (invocationCount = 3)
@Test (invocationCount = 7, threadPoolSize = 2)

TestNG Assertions

SoftAssert softassert= new SoftAssert();
 softassert.assertEquals(1, 1);
softassert.assertAll();
Assert.assertEquals(11, 11);
Assert.assertEquals(true, true, "Not Matching");

TestNG XML File

<suite name="TestNGSuite" parallel="methods" threadcount="4">
<listeners>
<listener class-name="packagename.classname"></listener>
</listeners>
<parameter name="Data1" value="10" />
 <parameter name="Data2" value="3" />
 <test name="TestNGTest">
 <groups>
 <run>
 <exclude name="Test.*" />
 <include name="SmokeTest" />
 </run>
 </groups>
 <classes>
 <class name="packagename.classname"/>
 </classes>
 </test> <!-- TestNGTest -->
</suite> <!-- TestNGSuite -->

All Maven Dependency

<dependencies>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
                <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.2.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.1</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
                <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>
                <!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>5.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/htmlunit-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>3.62.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
                <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.1</version>
</dependency>
                <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
                <dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>2.0.0</version>
</dependency>

</dependencies>

All Excel Read and Write Features Class


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;

import org.apache.poi.common.usermodel.Hyperlink;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;



@SuppressWarnings("deprecation")
public class AllreadWriteExcelFeatures {


public  String path;
public  FileInputStream fis = null;
public  FileOutputStream fileOut =null;
private XSSFWorkbook workbook = null;
private XSSFSheet sheet = null;
private XSSFRow row   =null;
private XSSFCell cell = null;

//calling constructor 
public readWriteExcel(String path) {

this.path=path;
try {
fis = new FileInputStream(path);
workbook = new XSSFWorkbook(fis);
sheet = workbook.getSheetAt(0);
fis.close();
}
catch (Exception e) 
{
e.printStackTrace();
}



// Returns the row count in a sheet
public int getRowCount(String sheetName){
int index = workbook.getSheetIndex(sheetName);
if(index==-1)
return 0;
else{
sheet = workbook.getSheetAt(index);
int number=sheet.getLastRowNum()+1;
return number;
}
}

// Returns the data from a cell with parameter sheet name, column name and row number
public String getCellData(String sheetName,String colName,int rowNum){
try{
if(rowNum <=0)
return "";

int index = workbook.getSheetIndex(sheetName);
int col_Num=-1;
if(index==-1)
return "";

sheet = workbook.getSheetAt(index);
row=sheet.getRow(0);
for(int i=0;i<row.getLastCellNum();i++){
//System.out.println(row.getCell(i).getStringCellValue().trim());
if(row.getCell(i).getStringCellValue().trim().equals(colName.trim()))
col_Num=i;
}
if(col_Num==-1)
return "";

sheet = workbook.getSheetAt(index);
row = sheet.getRow(rowNum-1);
if(row==null)
return "";
cell = row.getCell(col_Num);

if(cell==null)
return "";

if(cell.getCellType()==CellType.STRING)
return cell.getStringCellValue();
else if(cell.getCellType()==CellType.NUMERIC || cell.getCellType()==CellType.FORMULA ){

String cellText  = String.valueOf(cell.getNumericCellValue());
if (HSSFDateUtil.isCellDateFormatted(cell)) {

double d = cell.getNumericCellValue();

Calendar cal =Calendar.getInstance();
cal.setTime(HSSFDateUtil.getJavaDate(d));
cellText =
(String.valueOf(cal.get(Calendar.YEAR))).substring(2);
cellText = cal.get(Calendar.DAY_OF_MONTH) + "/" +
cal.get(Calendar.MONTH)+1 + "/" + 
cellText;
}
return cellText;
}else if(cell.getCellType()==CellType.BLANK)
return ""; 
else 
return String.valueOf(cell.getBooleanCellValue());
}
catch(Exception e){
e.printStackTrace();
return "row "+rowNum+" or column "+colName +" does not exist in xls";
}
}



// returns the data from a cell with parameter sheet name, column number and row number
public String getCellData(String sheetName,int colNum,int rowNum){
try{
if(rowNum <=0)
return "";

int index = workbook.getSheetIndex(sheetName);

if(index==-1)
return "";
sheet = workbook.getSheetAt(index);
row = sheet.getRow(rowNum);
if(row==null)
return "";
cell = row.getCell(colNum);
if(cell==null)
return "";

if(cell.getCellType()==CellType.STRING)
return cell.getStringCellValue();
else if(cell.getCellType()==CellType.NUMERIC || cell.getCellType()==CellType.FORMULA ){

String cellText  = String.valueOf(cell.getNumericCellValue());
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// format in form of M/D/YY
double d = cell.getNumericCellValue();

Calendar cal =Calendar.getInstance();
cal.setTime(HSSFDateUtil.getJavaDate(d));
cellText =
(String.valueOf(cal.get(Calendar.YEAR))).substring(2);
cellText = cal.get(Calendar.MONTH)+1 + "/" +
cal.get(Calendar.DAY_OF_MONTH) + "/" +
cellText;
}
return cellText;
}else if(cell.getCellType()==CellType.BLANK)
return "";
else 
return String.valueOf(cell.getBooleanCellValue());
}
catch(Exception e){

e.printStackTrace();
return "row "+rowNum+" or column "+colNum +" does not exist  in xls";
}
}




// returns true if data is set successfully else false with string data
public boolean setCellData(String sheetName,String colName,int rowNum, String data){
try{
fis = new FileInputStream(path); 
workbook = new XSSFWorkbook(fis);

if(rowNum<=0)
return false;

int index = workbook.getSheetIndex(sheetName);
int colNum=-1;
if(index==-1)
return false;


sheet = workbook.getSheetAt(index);


row=sheet.getRow(0);
for(int i=0;i<row.getLastCellNum();i++){

try {

//System.out.println(row.getCell(i).getStringCellValue());
if(row.getCell(i).getStringCellValue().trim().equals(colName))
colNum=i;
} catch (Exception e) {
// TODO: handle exception
}

}

if(colNum==-1)
return false;

sheet.autoSizeColumn(colNum); 

row = sheet.getRow(rowNum);
if (row == null)
row = sheet.createRow(rowNum);

cell = row.getCell(colNum);
if (cell == null)
cell = row.createCell(colNum);


cell.setCellValue(data);

fileOut = new FileOutputStream(path);

workbook.write(fileOut);

fileOut.close();

}
catch(Exception e){
e.printStackTrace();
return false;
}
return true;
}



// returns true if data is set successfully else false with string array data
public boolean setCellData(String sheetName,String colName, List<Object> link){
try{
fis = new FileInputStream(path); 
workbook = new XSSFWorkbook(fis);



int index = workbook.getSheetIndex(sheetName);
int colNum=-1;
if(index==-1)
return false;


sheet = workbook.getSheetAt(index);


row=sheet.getRow(0);
for(int i=0;i<row.getLastCellNum();i++){

try {

//System.out.println(row.getCell(i).getStringCellValue());
if(row.getCell(i).getStringCellValue().trim().equals(colName))
colNum=i;
} catch (Exception e) {
// TODO: handle exception
}

}
if(colNum==-1)
return false;

sheet.autoSizeColumn(colNum); 

for (int i = 0; i < link.size(); i++) {


row = sheet.getRow(i+1);
if (row == null)
row = sheet.createRow(i+1);

cell = row.getCell(colNum);
if (cell == null)
cell = row.createCell(colNum);


cell.setCellValue((String)link.get(i));

}
fileOut = new FileOutputStream(path);

workbook.write(fileOut);

fileOut.close();

}
catch(Exception e){
e.printStackTrace();
return false;
}
return true;
}



public boolean setCellData(String sheetName,int colNum,int rowNum, String data){
try{
fis = new FileInputStream(path); 
workbook = new XSSFWorkbook(fis);

if(rowNum<0)
return false;

int index = workbook.getSheetIndex(sheetName);
//int colNum=-1;
if(index==-1)
return false;


sheet = workbook.getSheetAt(index);

if(colNum==-1)
return false;

sheet.autoSizeColumn(colNum); 
row = sheet.getRow(rowNum);
if (row == null)
row = sheet.createRow(rowNum);

cell = row.getCell(colNum);
if (cell == null)
cell = row.createCell(colNum);


cell.setCellValue(data);

fileOut = new FileOutputStream(path);

workbook.write(fileOut);

fileOut.close();

}
catch(Exception e){
e.printStackTrace();
return false;
}
return true;
}


// returns true if sheet is created successfully else false
public boolean addSheet(String  sheetname){

FileOutputStream fileOut;
int index = workbook.getSheetIndex(sheetname);
try {
if(index>0) {
return true;
}
workbook.createSheet(sheetname);
fileOut = new FileOutputStream(path);
workbook.write(fileOut);
fileOut.close();     
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}

// returns true if sheet is removed successfully else false if sheet does not exist
public boolean removeSheet(String sheetName){
int index = workbook.getSheetIndex(sheetName);
if(index==-1)
return false;

FileOutputStream fileOut;
try {
workbook.removeSheetAt(index);
fileOut = new FileOutputStream(path);
workbook.write(fileOut);
fileOut.close();     
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
// returns true if column is created successfully
public boolean addColumn(String sheetName,String colName){


try{
fis = new FileInputStream(path); 
workbook = new XSSFWorkbook(fis);
int index = workbook.getSheetIndex(sheetName);
if(index==-1)
return false;

XSSFCellStyle style = workbook.createCellStyle();
//style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
//style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

sheet=workbook.getSheetAt(index);

row = sheet.getRow(0);
if (row == null)
row = sheet.createRow(0);


if(row.getLastCellNum() == -1)
cell = row.createCell(0);
else
cell = row.createCell(row.getLastCellNum());

cell.setCellValue(colName);
cell.setCellStyle(style);

fileOut = new FileOutputStream(path);
workbook.write(fileOut);
fileOut.close();     

}catch(Exception e){
e.printStackTrace();
return false;
}

return true;


}

// removes a column and all the contents
public boolean removeColumn(String sheetName, int colNum) {
try{
if(!isSheetExist(sheetName))
return false;
fis = new FileInputStream(path); 
workbook = new XSSFWorkbook(fis);
sheet=workbook.getSheet(sheetName);
XSSFCellStyle style = workbook.createCellStyle();
//style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
@SuppressWarnings("unused")
XSSFCreationHelper createHelper = workbook.getCreationHelper();
//style.setFillPattern(HSSFCellStyle.NO_FILL);
for(int i =0;i<getRowCount(sheetName);i++){
row=sheet.getRow(i);
if(row!=null){
cell=row.getCell(colNum);
if(cell!=null){
cell.setCellStyle(style);
row.removeCell(cell);
}
}
}
fileOut = new FileOutputStream(path);
workbook.write(fileOut);
fileOut.close();
}
catch(Exception e){
e.printStackTrace();
return false;
}
return true;

}
// find  sheets name is exists
public boolean isSheetExist(String sheetName){
int index = workbook.getSheetIndex(sheetName);
if(index==-1){
index=workbook.getSheetIndex(sheetName.toUpperCase());
if(index==-1)
return false;
else
return true;
}
else
return true;
}
// returns number of columns in a sheet
public int getColumnCount(String sheetName){
// check if sheet exists
if(!isSheetExist(sheetName))
return -1;

sheet = workbook.getSheet(sheetName);
row = sheet.getRow(0);

if(row==null)
return -1;

return row.getLastCellNum();

}


//String sheetName, String testCaseName,String keyword ,String URL,String message
public boolean addHyperLink(String sheetName,String screenShotColName,String testCaseName,int index,String url,String message){
url=url.replace('\\', '/');
if(!isSheetExist(sheetName))
return false;

sheet = workbook.getSheet(sheetName);

for(int i=2;i<=getRowCount(sheetName);i++){
if(getCellData(sheetName, 0, i).equalsIgnoreCase(testCaseName)){

setCellData(sheetName, screenShotColName, i+index, message,url);
break;
}
}

return true; 
}
public int getCellRowNum(String sheetName,String colName,String cellValue){

for(int i=2;i<=getRowCount(sheetName);i++){
if(getCellData(sheetName,colName , i).equalsIgnoreCase(cellValue)){
return i;
}
}
return -1;

}

public  boolean  addHLsheet(String sheetName) {

//Hyperlink urlLink= new Hyperlink();

int index = workbook.getSheetIndex(sheetName);
sheet = workbook.getSheetAt(index);

//Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
Hyperlink hyperlinks = sheet.getHyperlink(1, 1);
hyperlinks.setAddress("www.taxmann.com");

// HSSFHyperlink url_link=new HSSFHyperlink(HSSFHyperlink.LINK_URL);


return true;
}

// to run this on stand alone
public static void main(String arg[]) throws IOException{


readWriteExcel datatable = null;


datatable = new readWriteExcel("");
for(int col=0 ;col< datatable.getColumnCount("TC5"); col++){
System.out.println(datatable.getCellData("TC5", col, 1));
}
}


}

Mithun Kumar

I am Mithun Kumar, a freelance and working software professional. I have around 6 years of experience in software Quality Assurance in Manual and Automation with Various tools and Technology. I am always learning new technologies and find myself up to date with the latest software technologies.

Post a Comment

Thanks! for you valuable comment.

Previous Post Next Post