添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
爱跑步的钥匙  ·  MybatisPlus学习笔记 | ...·  2 周前    · 
咆哮的馒头  ·  Get Nth Entry from ...·  2 周前    · 
留胡子的汤圆  ·  SharePoint 搜索 REST ...·  1 周前    · 
没有腹肌的开水瓶  ·  Exception in thread ...·  1 周前    · 
英勇无比的莴苣  ·  Better error message ...·  14 小时前    · 
傻傻的风衣  ·  Best way to convert ...·  5 月前    · 
成熟的打火机  ·  Golang RSA ...·  10 月前    · 

Cannot get a STRING value from a NUMERIC cell : This is the error i get when i try to get data from Excel using selenium Java how to resolve

i am a beginner this is the code i used

package testcases;
import org.testng.annotations.Test;
import testutils.ExcelDataRead;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
public class Excel_reading_register_demo2 {
    WebDriver driver;
    WebDriverWait wait;
    public ExcelDataRead excelObj;
    String xlFilePath ="testdata//excel_reading_register_demo2.xlsx";
    String sheetName = "Sheet1";
    @DataProvider(name="userData")
     @Test(priority = 2)
    public Object[][] userFormData() throws Exception
        Object[][] data = testData(xlFilePath, sheetName);
        return data;
    public Object[][] testData(String xlFilePath, String sheetName) throws Exception//User Defined Method
        excelObj = new ExcelDataRead(xlFilePath);
        int rows = excelObj.getRowCount(sheetName);
        int columns = excelObj.getColumnCount(sheetName);
        Object[][] excelData = new Object[rows-1][columns]; 
        for(int i=1; i<rows; i++)
            for(int j=0; j<columns; j++)
                excelData[i-1][j] = excelObj.getCellData(sheetName, i, j);
        return excelData;
     @Test(dataProvider = "userData",priority = 1)
        public void f(String firstName, String lastName, CharSequence[] phoneNum, String gmail, String address,  
                String cityN, String stateN, CharSequence[] postcodeN,String userName, String passWord, String passWord1) throws
        InterruptedException
         driver.findElement(By.linkText("REGISTER")).click(); 
            driver.findElement(By.name("firstName")).sendKeys(firstName);
            driver.findElement(By.name("lastName")).sendKeys(lastName);
            driver.findElement(By.name("phone")).sendKeys(phoneNum);
            driver.findElement(By.name("userName")).sendKeys(gmail);
            driver.findElement(By.name("address1")).sendKeys(address);
            driver.findElement(By.name("city")).sendKeys(cityN);
            driver.findElement(By.name("state")).sendKeys(stateN);
            driver.findElement(By.name("postalCode")).sendKeys(postcodeN);
            driver.findElement(By.name("email")).sendKeys(userName);
            driver.findElement(By.name("password")).sendKeys(passWord);
            driver.findElement(By.name("confirmPassword")).sendKeys(passWord1);
            driver.findElement(By.name("submit")).click();
            Thread.sleep(7000);
            driver.findElement(By.linkText("REGISTER")).click();
  @Parameters("browser")
  @BeforeTest
  public void beforeTest(String browser) {
      if(browser.equals("firefox"))
      System.setProperty("webdriver.gecko.driver","drivers\\geckodriver.exe");
      driver=new FirefoxDriver();
      else if(browser.equals("chrome"))
      System.setProperty("webdriver.chrome.driver","drivers\\chromedriver.exe");
      driver=new ChromeDriver();
      driver.get("http://demo.guru99.com/test/newtours/");
      wait=new WebDriverWait(driver,20);
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  @AfterTest
  public void afterTest() {
      driver.close();

This is the error which i get :

error793×185 92.3 KB

When debugging your code, try and break it down, starting with the stack trace and line number to figure out what the issue is.

In this case, the exception tells you the problem “Cannot get a STRING value from a NUMERIC cell”, so it’s a type issue. The cell is formatted as numeric in the spreadsheet, while the code is expecting strings.

While it’s not clear what testutils.ExcelDataRead is based on, you can probably improve the getCellData() method in it to handle different column types from Excel, rather that it assuming that everything will be string data.