Question

I am trying to import login credential like: username and password using xsl sheet, by using below code but I got NoSuchElementException exception while running,

my xsl sheet looks like:

  username    |  password
--------------------------
jan30selenium | selenium

am using:

  • eclipse
  • webdriver.iostream
  • selenium tool

Login.java:

package Iostream;

import java.io.FileInputStream;

import jxl.Sheet;
import jxl.Workbook;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class Login {

  public WebDriver driver;

  @Test
  public void f()throws Exception {
      FileInputStream fi=new FileInputStream("E:\\workspace1\\SeleniumAutomation\\test data\\login.xls");
      Workbook w= Workbook.getWorkbook(fi);
      Sheet s=w.getSheet(0);
      driver.findElement(By.id("f_id")).sendKeys(s.getCell(0,1).getContents());
      driver.findElement(By.id("f_pwd")).sendKeys(s.getCell(1,0).getContents());
      Thread.sleep(5000);
      driver.findElement(By.linkText("input.signin")).click();
      Thread.sleep(3000);
  }

  @BeforeTest
  public void beforeTest() {
      System.setProperty("webdriver.chrome.driver","\\E:\\lib\\chromedriver.exe");
      driver=new ChromeDriver();
      driver.get("http://www.gmail.com");
  }

  @AfterTest
  public void afterTest() {
  }
}

Exception is:

Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\User\AppData\Local\Temp\scoped_dir5352_17443}, rotatable=false, locationContextEnabled=true, version=33.0.1750.154, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:348)
    at org.openqa.selenium.By$ById.findElement(By.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
    at Iostream.Login.f(Login.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    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:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    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.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

Where is the problem?

Was it helpful?

Solution

You are getting that issue, because when you get("http://gmail.com/") the id's ("f_id" and "f_pwd" are not there.

If your intention is to log in, then you should probably be more specific with your URL, and you should use the following code:

  @Test
  public void f()throws Exception {
      FileInputStream fi=new FileInputStream("E:\\workspace1\\SeleniumAutomation\\test data\\login.xls");
      Workbook w= Workbook.getWorkbook(fi);
      Sheet s=w.getSheet(0);
      driver.findElement(By.id("Email")).sendKeys(s.getCell(0,1).getContents());
      driver.findElement(By.id("Passwd")).sendKeys(s.getCell(1,0).getContents());
      Thread.sleep(5000);
      driver.findElement(By.cssSelector("input#signIn")).click();
      Thread.sleep(3000);
      }
  @BeforeTest
  public void beforeTest() {
      System.setProperty("webdriver.chrome.driver","\\E:\\lib\\chromedriver.exe");
      driver=new ChromeDriver();
      driver.get("https://accounts.google.com/ServiceLogin?service=mail");
  }

Also, you'll note when clicking the login button, you were looking for a link with the TEXT "input.signin" I think what you meant to do, is a CSS selector input with a class of signin but that element doesn't exist either.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top