/I am using the following code to get the cookie value but I am only getting 1st and 2nd part.But not getting 3rd and 4th part(null as you can see).
Please help me with this.I have attached the screenshot of the cookies i get manually/
WebDriver driver;
System.setProperty("webdriver.ie.driver",
"C:\\Users\\MR049860\\Documents\\Selenium\\IEDriverServer\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get("https://www.example.com");
// Input Email id and Password If you are already Register
driver.findElement(By.name("j_username")).sendKeys("publisher");
driver.findElement(By.name("j_password")).sendKeys("Passw0rd");
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("BtnButton__")));
// WebElement ele = driver.findElement(By.id("ctllogonBtnButton__"));
element.sendKeys(Keys.ENTER);
// create file named Cookies to store Login Information
File file = new File("madhu.data");
try
{
// Delete old file if exists
file.delete();
file.createNewFile();
FileWriter fileWrite = new FileWriter(file);
BufferedWriter Bwrite = new BufferedWriter(fileWrite);
// loop for getting the cookie information
// loop for getting the cookie information
for(Cookie ck : driver.manage().getCookies())
{
Bwrite.write((ck.getName()+";"+ck.getValue()+";"+ck.getDomain()+";"+ck.getPath()+";"+ck.getExpiry()+";"+ck.isSecure()));
Bwrite.newLine();
}
Bwrite.close();
fileWrite.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
Output : -
ASPSESSIONIDSZQPRQCS;NFPFIAGDBMJNOMKPCPKESHDC;null;/;null;true
You can get only name and value. You are not allowed to get cookies of other domains/paths or expiry date. That's the security policy of web browsers.
Below code can be used to get the cookie value
package utility;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class CookieUtility {
public static InternetExplorerDriver getDriver() throws InterruptedException {
InternetExplorerDriver driver;
System.setProperty("webdriver.ie.driver",
"C:\\Documents\\Selenium\\IEDriverServer\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get("https://example.com");
// Input Email id and Password If you are already Register
driver.findElement(By.name("username")).sendKeys("password");
driver.findElement(By.name("password")).sendKeys("Paswrd");
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("logonButton")));
// WebElement ele = driver.findElement(By.id("ctllogonBtnButton__"));
element.sendKeys(Keys.ENTER);
for (int i = 0; i < 2 && driver.findElements(By.id("textbox")).size() == 0; i++) {
Thread.sleep(10000);
}
element.sendKeys(Keys.F5);
return driver;
}
public static String[] getCookieValues(InternetExplorerDriver driver) throws InterruptedException {
// create file named Cookies to store Login Information
Set<Cookie> cks = driver.manage().getCookies();
String[] cookieValues = new String[cks.size()];
int i = 0;
for (Cookie ck : cks) {
cookieValues[i] = ck.getValue();
i++;
}
i = 0;
return cookieValues;
}
public static String getSessionId(InternetExplorerDriver driver) {
String sessionId = driver.getSessionId().toString();
return sessionId;
}
public static void main(String args[]) throws InterruptedException {
InternetExplorerDriver driver = getDriver();
String[] values = getCookieValues(driver);
String sessionId = getSessionId(driver);
}
public static String getcookiestring(String sessionId, String cookie1, String cookie2, String cookie3) {
String cookie = "JSESSIONID=" + sessionId + "; hi.session.co.entity=" + cookie2 + "; hi.session.id.identifier="
+ cookie1 + "; hi.session.client.identifier=" + cookie3;
return cookie;
}
}
Related
I am trying to capture screenshot in Selenium, However I am getting an error on -File source = ts.getScreenshotAs(OutputType.FILE); I have searched the code online and it they have given it as it is. Now I don't know what should be replaced with this code. The error I am getting is- FILE cannot be resolved or is not a field. My full code is:
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.aventstack.extentreports.Status;
import com.google.common.io.Files;
import com.mongodb.MapReduceCommand.OutputType;
public class UtilityMethods extends ExtentReportBaseClass{
static WebDriver driver;
public static WebDriver openBrowser(String browsers) {
System.out.println("initiated browser is " + browsers);
if (browsers.equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.firefox.marionette", "");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
driver = new FirefoxDriver(opt);
}
else if (browsers.equalsIgnoreCase("Chrome")) {
// String driverPath = System.getProperty("user.dir") +
// "\\src\\Drivers\\chromedriver";
// System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
return driver;
}
public static void launchWebsite(String URL) {
driver.get(URL);
}
public static By locateByElement(String locator, String locatorValue) {
By by = null;
switch (locator) {
case "id":
by = By.id(locatorValue);
break;
case "name":
by = By.name(locatorValue);
break;
case "linktext":
by = By.linkText(locatorValue);
break;
case "partialLinkText":
by = By.partialLinkText(locatorValue);
break;
case "className":
by = By.className(locatorValue);
break;
case "tagName":
by = By.tagName(locatorValue);
break;
case "cssSelector":
by = By.cssSelector(locatorValue);
break;
case "xpath":
by = By.xpath(locatorValue);
break;
}
System.out.println("value of by is" + by);
return by;
}
public void sendDataById(String locatorValue, String userData) {
driver.findElement(By.id(locatorValue)).sendKeys(userData);
}
public void sendData(String element) {
String[] var = element.split("###");
String loctype = var[0];
String locval = var[1];
// System.out.println(locval);
String uservalue = var[2];
// System.out.println(locval);
// System.out.println(uservalue);
By locator = locateByElement(loctype, locval);
System.out.println(loctype);
System.out.println(locval);
driver.findElement(locator).sendKeys(uservalue);
}
public WebDriver getdriver() {
if (driver == null) {
driver = new FirefoxDriver();
return driver;
} else {
return driver;
}
}
public static String capture(WebDriver driver,String screenShotName) throws IOException
{
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest = System.getProperty("user.dir") +"/TestCasesScreenshot"+screenShotName+".png";
File destination = new File(dest);
Files.copy(source, destination);
return dest;
}
public void clickElement(String locElem) throws IOException {
try {
System.out.println(locElem);
String[] var = locElem.split("###");
String loctype = var[0];
String locval = var[1];
System.out.println(loctype);
System.out.println(locval);
By locator = locateByElement(loctype, locval);
driver.findElement(locator).click();
}
catch(Exception e)
{
System.out.println("Catched Exception, Element not found");
String screenShotPath = UtilityMethods.capture(driver, "screenShotName");
test.log(Status.FAIL, "Snapshot below: " + test.addScreenCaptureFromPath(screenShotPath));
}
}
}
You need to import selenium's OutputType. Use this -- import org.openqa.selenium.OutputType. Currently you have a mongodb class import.
I have been working on automated tests and are trying to skip the login page, by logging in one time, saving the cookies on a text file and then finally reading and adding the files on a new browser instance.
It works fine when I just create one browser at a time, but if I create multiple browser parallel, only one page receives the cookies (thus skipping the login page as intended).
Here is the code:
My Setup(). This works perfect. I just login, saves the cookie data in text file and close the browser.
#BeforeClass
public void cookie_setup(){
//Firefox
System.setProperty("webdriver.gecko.driver", "C:\\SeleniumGecko/geckodriver.exe");
webdriver = new FirefoxDriver();
File file = new File("Cookies.data");
try
{
file.delete();
file.createNewFile();
FileWriter fileWrite = new FileWriter(file);
BufferedWriter Bwrite = new BufferedWriter(fileWrite);
for ( Cookie ck: webdriver.manage().getCookies())
{
Bwrite.write((ck.getName()+";"+ck.getValue()+";"+ck.getDomain()+";"+ck.getPath()+";"+ck.getExpiry()+";"+ck.isSecure()));
Bwrite.newLine();
}
Bwrite.close();
fileWrite.close();
}catch (Exception ex)
{
ex.printStackTrace();
}
cookies = webdriver.manage().getCookies();
webdriver.quit();
}
Then I create a new firefox browser
Reads the cookie data in the text file
Add the the cookies to the page with:`webdriver.manage().addCookie(ck);
#Test(threadPoolSize = 4, invocationCount = 4)
public void search() throws InterruptedException {
System.setProperty("webdriver.gecko.driver",
"C:\\SeleniumGecko/geckodriver.exe");
webdriver.navigate().to("http://pagethatrequirelogin/");
try {
File file = new File("Cookies.data");
FileReader fileReader = new FileReader(file);
BufferedReader Buffreader = new BufferedReader(fileReader);
String strline;
while ((strline = Buffreader.readLine()) != null) {
StringTokenizer token = new StringTokenizer(strline, ";");
while (token.hasMoreTokens()) {
String name = token.nextToken();
String value = token.nextToken();
String domain = token.nextToken();
String path = token.nextToken();
Date expiry = null;
String val;
if (!(val = token.nextToken()).equals("null")) {
expiry = new Date(val);
}
Boolean isSecure = Boolean.valueOf(token.nextToken());
Cookie ck = new Cookie(name, value, domain, path, expiry, isSecure);
System.out.println(ck);
webdriver.manage().addCookie(ck);
}
}
}
catch(Exception ex){
}
}
I use TestNG and with the parameters:
#Test(threadPoolSize = 4, invocationCount = 4)
I create 4 firefox browers at the same time, but only one of browser receives the cookies and skip login page.
It works perfectly fine if I just create one browser at a time multiple times.
The issue is because you are perhaps having your #Test methods overwrite the webdriver instance. Here's a sample that shows how a thread-safe version of it would look like:
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
public class CookiesSample {
private static final ThreadLocal<WebDriver> drivers = new ThreadLocal<>();
private List<Cookie> cookies = new ArrayList<>();
#BeforeClass
public void beforeClass() throws IOException {
String text = "Cookies.data";
List<String> lines = Files.readAllLines(Paths.get(text));
lines.forEach(line -> {
StringTokenizer token = new StringTokenizer(line, ";");
while (token.hasMoreTokens()) {
String name = token.nextToken();
String value = token.nextToken();
String domain = token.nextToken();
String path = token.nextToken();
Date expiry = null;
String val = token.nextToken();
if (!val.equals("null")) {
expiry = asDate(val);
}
Boolean isSecure = Boolean.valueOf(token.nextToken());
Cookie ck = new Cookie(name, value, domain, path, expiry, isSecure);
cookies.add(ck);
}
});
}
#BeforeMethod
public void beforeMethod() {
WebDriver driver = new FirefoxDriver();
cookies.forEach(driver.manage()::addCookie);
drivers.set(driver);
}
#AfterMethod
public void afterMethod() {
drivers.get().quit();
drivers.remove();
}
#Test(threadPoolSize = 4, invocationCount = 4)
public void testMethod() {
drivers.get().get("http://pagethatrequirelogin/");
}
private static Date asDate(String text) {
try {
return DateFormat.getInstance().parse(text);
} catch (ParseException e) {
return new Date();
}
}
}
package testPackage;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.*;
public class AllLinkVerificationInAPage {
WebDriver driver;
#BeforeTest
public void OpenApp()
{
System.setProperty("webdriver.chrome.driver", "E:/Selenium/Webdriver /Softwares/chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("http://ndtv.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement popUp = driver.findElement(By.xpath("//*[#id='__cricketsubscribe']/div[2]/div[2]/a[1]"));
popUp.click();
}
#Test
public void clickLinks() throws InterruptedException
{
//extract the list of WenElements and its count
List<WebElement> linkElements = driver.findElements(By.tagName("a"));
int count = linkElements.size();
System.out.println("Total number of links = " + count );
//test each link
for(WebElement currentElement : linkElements)
{
String link = currentElement.getText();
System.out.println(link);
if(link !="")
{
currentElement.click();
System.out.println("Working Fine");
}
driver.navigate().back();
Thread.sleep(3000);
}
}
}
When I run this code I get following error:-
org.openqa.selenium.StaleElementReferenceException: stale element
reference: element is not attached to the page document
I tried with implicit wait as well but getting same issue.
Each time the DOM is changed or refreshed, like in going to different page, the driver loses the elements it previously located. You need to relocate the list each iteration
int count = driver.findElements(By.tagName("a")).size();
for (int i = 0 ; i < count ; ++i) {
List<WebElement> linkElements = driver.findElements(By.tagName("a"));
WebElement currentElement = linkElements.get(i);
String link = currentElement.getText();
System.out.println(link);
if(link != "")
{
currentElement.click();
System.out.println("Working Fine");
}
driver.navigate().back();
Thread.sleep(3000);
}
Can someone help with it ?
I have error
"Exception in thread “main” org.openqa.selenium.StaleElementReferenceException: Element not found in the cache"
Why showing this error?
I need to hover on each category menu than click on each text in sub-menu.
public class santander {
private static WebDriver driver = null;
public static JavascriptExecutor js = (JavascriptExecutor) driver;
public static void main(String[] args) throws FileNotFoundException, InterruptedException, IOException {
// TODO Auto-generated method stub
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.santander.co.uk/uk/index");
driver.manage().window().maximize();
driver.get("http://www.santander.co.uk/uk/index");
JavascriptExecutor js = (JavascriptExecutor) driver;
WebDriverWait wait = new WebDriverWait(driver, 10);
String submenutxtlinks = "submenu.txt";
List<String> submenu = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader(submenutxtlinks));
String line;
while ((line = reader.readLine()) != null) {
submenu.add(line);
}
reader.close();
Actions action = new Actions(driver);
/*
WebElement menu = driver.findElement(By.linkText("Current Accounts"));
action.moveToElement(menu).perform();
WebElement submenu = driver.findElement(By.linkText("See all current accounts"));
action.moveToElement(submenu);
action.click();
action.perform();
*/
// String title = driver.getTitle();
// wait.until(ExpectedConditions.titleIs(title));
// driver.navigate().back();
//Loop to read all lines one by one from file and print It.
// while((menu = BR.readLine())!= null && !menu.isEmpty()){
// driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Action hovering = action.moveToElement(a).build();
// hovering.perform();
//action.moveToElement(a).perform();
//action.clickAndHold(a).perform();
WebElement a = driver.findElement(By.cssSelector("#nav > div.navMain > div.nav_menu > nav > ul > li:nth-child(1) > a"));
Action hovering = action.moveToElement(a).build();
//Thread.sleep(2000);
for (int i=0;i<=submenu.size()-1;i++ ) {
//String b = submenu.get(i);
// System.out.println(b);
//WebElement b = driver.findElement(By.xpath(submenu.get(i)));
try{
//Your code which causes exception
hovering.perform();
//action.moveToElement(b).click(b).build().perform();
Thread.sleep(1000);
clickAnElementByLinkText(submenu.get(i));
//b.click();
Thread.sleep(1000);
/*
wait.until(ExpectedConditions.visibilityOf(b));
action.moveToElement(b);
action.click();
action.perform();
*/
// wait.until(ExpectedConditions.titleIs(title));
driver.navigate().back();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Thread.sleep(2000);
// driver.get("http://www.santander.co.uk/uk/index");
//driver.navigate();
Thread.sleep(2000);
// driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
catch(org.openqa.selenium.StaleElementReferenceException e){
//Repeat the code in try
}
}
// }
driver.close();
}
public static void clickAnElementByLinkText(String linkText) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(linkText)));
driver.findElement(By.xpath(linkText)).click();
}
}
Dont mix ImplicitWait ExplicitWait and Thread.Sleep all in the same context.
Learn when and where those should be used.
The hoverElement wont work because the driver navigates to different page and element no longer exists you have find it again inside the forLoop
For the sake of test I've hardcoded the submenulist
This code will do what you've asked for
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ListTest {
static WebDriver driver;
public static void main(String[] args) {
List<String> submenu = new ArrayList<>(Arrays.asList(new String[]{"See all current accounts", "1|2|3 Current Account", "Everyday Current Account", "Basic Current Account", "Choice Current Account"}));
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.santander.co.uk/uk/index");
for (String sMenu : submenu) {
WebElement a = driver.findElement(By.cssSelector("#nav > div.navMain > div.nav_menu > nav > ul > li:nth-child(1) > a"));
new Actions(driver).moveToElement(a).build().perform();
clickAnElementByLinkText("//li[#role='listitem']/a[normalize-space(text())='" + sMenu + "']");
driver.navigate().back();
}
driver.quit();
}
public static void clickAnElementByLinkText(String linkText) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(linkText))).click();
}
}
You are trying to access an element which does not exists.
The code collects the elements on the page,
then the code clicks an element which changes the source
then it try to access an object he collected before but it is not longer there (what you see is a new one).
You can enter the finding of the elements process into the loop and loop changing the 'i' element in every iteration (If you must click the element in every iteration).
i am getting somthing like this
Hi i am scraping a web page using Selenium Webdriver an i am able to achieve my data but problem is that this directly interact with browser and i dont want to open a web browser and want to scrape all data as it is
How can i achieve my goal
Here is my code
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class GetData {
public static void main(String args[]) throws InterruptedException {
String sDate = "27/03/2014";
WebDriver driver = new FirefoxDriver();
String url="http://www.upmandiparishad.in/commodityWiseAll.aspx";
driver.get(url);
Thread.sleep(5000);
// select barge
new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys(sDate);
// click buttonctl00_ContentPlaceHolder1_txt_rate
Thread.sleep(3000);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
Thread.sleep(5000);
//get only table tex
WebElement findElement = driver.findElement(By.id("ctl00_ContentPlaceHolder1_GridView1"));
String htmlTableText = findElement.getText();
// do whatever you want now, This is raw table values.
System.out.println(htmlTableText);
driver.close();
driver.quit();
}
}
My updated New code
import com.gargoylesoftware.htmlunit.BrowserVersion;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
public class Getdata1 {
public static void main(String args[]) throws InterruptedException {
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
driver.get("http://www.upmandiparishad.in/commodityWiseAll.aspx");
System.out.println(driver.getPageSource());
Thread.sleep(5000);
// select barge
new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
String sDate = "12/04/2014"; //What date you want
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys(sDate);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
Thread.sleep(3000);
//get only table tex
WebElement findElement = driver.findElement(By.id("ctl00_ContentPlaceHolder1_GridView1"));
String htmlTableText = findElement.getText();
// do whatever you want now, This is raw table values.
System.out.println(htmlTableText);
driver.close();
driver.quit();
}
}
Thanks in advance
Use HtmlUnit or HtmlUnitDriver by Selenium
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_17);
driver.get("http://www.upmandiparishad.in/commodityWiseAll.aspx");
System.out.println(driver.getPageSource());
Thread.sleep(5000);
// select barge
new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
String sDate = "12/04/2014"; //What date you want
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys(sDate);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
Thread.sleep(3000);
//get only table tex
WebElement findElement = driver.findElement(By.id("ctl00_ContentPlaceHolder1_GridView1"));
String htmlTableText = findElement.getText();
// do whatever you want now, This is raw table values.
System.out.println(htmlTableText);
driver.close();
driver.quit();
To get tabular output, you can try something like this..
String arrCells[] = htmlTableText.split(" ");
Boolean bIsANumber = false;
for(int i = 0; i < arrCells.length; i++) {
try {
int tmp = Integer.parseInt(arrCells[i]);
bIsANumber = true;
}
catch(Exception ex) {
bIsANumber = false;
}
if(bIsANumber) {
System.out.print("\n"+arrCells[i]+"\t");
}
else {
System.out.print(arrCells[i]+"\t");
}
}