0

enter image description hereWorking on Page Object Model by using Data driven Framework, fetching data from Excel sheet.When executing the test script the mobile number displays like 9.5512395512E9.

In excel sheet Original Mobile Number is -955123955123

Running the Script it displays in the Mobile number field like 9.5512395512E9

TestUtilCode

public static Object[][] getTestData(String sheetName)
{
    FileInputStream fis=null;
    try
    {
        fis= new FileInputStream(TESTDATA_SHEET_PATH);
    }
    catch(FileNotFoundException e)
    {
        e.printStackTrace();
    }
    try
    {
        book=WorkbookFactory.create(fis);
    }
    catch(InvalidFormatException e)
    {
        e.printStackTrace();
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
     catch(NullPointerException e)
    {
         e.printStackTrace();
    }
    sheet = book.getSheet(sheetName);

    Object[][] data= new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];
    for(int i=0;i<sheet.getLastRowNum();i++)
    {
        for(int k=0;k<sheet.getRow(0).getLastCellNum(); k++)
        {
            data[i][k]=sheet.getRow(i + 1).getCell(k).toString();
        }
    }
    return data;
}

    }


**Regpage.java**
public class Regpage extends Testbase{
    @FindBy(xpath="//*[@id='section']/div/h2") WebElement Register;
    @FindBy(xpath="//input[@placeholder='First Name']") WebElement FName;
    @FindBy(xpath="//input[@placeholder='Last Name']") WebElement LName;
    @FindBy(xpath="//*[@id='basicBootstrapForm']/div[2]/div/textarea") WebElement Address;
    @FindBy(xpath="//input[@type='email']") WebElement Email;
    @FindBy(xpath="//input[@type='tel']") WebElement Phone;
    @FindBy(id="msdd")WebElement Language;
    @FindBy(id="countries")WebElement Country;
    @FindBy(id="submitbtn")WebElement SubmitButton;


public  Regpage()
{
PageFactory.initElements(driver, this);
}

public  String verifyPageTitle()
{
return driver.getTitle();
}

public String verifyRegisterForm()
{
    return driver.getTitle();
}

public void createNewReg(String ftName,String ltName,String ads,String emailAd,String phone,String lang,String sCon)
{
    FName.sendKeys(ftName);
    LName.sendKeys(ltName);
    Address.sendKeys(ads);
    Email.sendKeys(emailAd);
    Phone.sendKeys(phone);
    Language.sendKeys(lang);
    Country.sendKeys(sCon);
    SubmitButton.click();



}
}

RegpageTest.java

public class RegpageTest extends Testbase{
    Loginpage loginpage;
    Regpage regpage;
    Testutil testutil;
    String sheetName="Sheet1";

    public RegpageTest()
    {
    super();
    }

    @BeforeMethod
    public void setUp()
    {
        initialization();
        loginpage = new Loginpage();
        regpage= new Regpage();
        testutil= new Testutil();
        regpage=loginpage.Emailid(prop.getProperty("emailid"));

    }

    @Test(priority=1)
    public void verifyResgisterPageTitleTest()
    {
        String RegTitle =regpage.verifyPageTitle();
        Assert.assertEquals(RegTitle, "Register");
    }

    @DataProvider
    public Object[][] getATTestData()
    {
        Object data[][]=Testutil.getTestData(sheetName);
        return data;
    }

    @Test(priority=2,dataProvider="getATTestData") 
    public void validateCreateNewReg(String FirstName,String LastName,String Address, String EmailAddress,String Phone,String Language,String sCountry)
    {
        regpage.createNewReg(FirstName, LastName, Address, EmailAddress, Phone, Language, sCountry);
    }

//  @AfterMethod
    public void tearDown()
    {
    driver.quit();
    }
}

Error Message

org.openqa.selenium.WebDriverException: unknown error: cannot focus element (Session info: chrome=70.0.3538.67) (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:25:02.294Z' System info: host: 'REDDY', ip: '192.168.43.14', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_171' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.36.540470 (e522d04694c7eb..., userDataDir: C:\Users\lenovo\AppData\Loc...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 70.0.3538.67, webStorageEnabled: true} Session ID: c7b6f2c4cd2c57259f8e0997f3b03746 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279) at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51) at com.sun.proxy.$Proxy9.sendKeys(Unknown Source) at com.qa.pages.Regpage.createNewReg(Regpage.java:43) at com.qa.test.RegpageTest.validateCreateNewReg(RegpageTest.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:348) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305) at org.testng.SuiteRunner.run(SuiteRunner.java:254) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

1
  • Add your code or question will get closed.
    – FDM
    Oct 24, 2018 at 7:06

2 Answers 2

1

" ` "

. Add this special character present in the quotes. Since the mobile number field is an integer this error is throwing. If you add that special character then the cell will became as string.

0

You can add

'

to avoid such kind of issues. You can try converting cell value to String after fetching it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.