Caused by: org.openqa.selenium.NoSuchElementException: No such element



  • Java Code:

    @Test
        public void enterApplicationCerdentials(String userName, String password) {
    
            WebElement element;
            WebDriverWait wait = new WebDriverWait(driver, 100);
            element= wait.until(ExpectedConditions.elementToBeClickable(By.id("UserID")));
            System.out.println("--"+element);
    
    
             driver.findElement(By.xpath("//input[@name='userID']")).sendKeys("6776440202");
             driver.findElement(By.name("Password")).sendKeys(password);
             driver.findElement(By.xpath("//input[@id='UserName' and @name='UserName']")).sendKeys("Sydney");
            captureScreen();
    
    
    **HTML File:**
    
       <frameset rows="*, 1">
    <frame src="Script/Login.asp?">
    #document
    <html><head>
    <body onload="OnLoad()" topmargin="0" leftmargin="0" bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" alink="#000000">
    <div id="login">
    <div class="tintedBox" id="loginBox">
    <h1></h1>
    
    <form name="form" action="Login.asp?" method="post">
      <input type="hidden" name="Autologout" value="false">
      <input type="hidden" name="Division" value="">
      <span class="error"></span>
      <table>
          <tbody><tr>
              <td>User ID</td>
              <td><input type="text" size="30" id="UserID" name="UserID" value=""></td>
          </tr>
          <tr>
              <td>Password</td>
              <td><input type="password" size="30" id="Password" name="Password" value=""></td>
          </tr>
              <tr>
              <td>Last Name/Location</td>
              <td><input type="text" size="30" id="UserName" name="UserName" value=""></td>
          </tr>
      </tbody></table>
      <br>
      <font color="#d12b2c"><nobr>Your Last Name and Location are now mandatory to access the platform, simply</nobr><br>enter the details in field (e.g. Smith/Perth)</font>
      <br><br>
      <div>
        <input type="checkbox" id="SaveLogin" name="SaveLogin" value="SaveLogin"><label for="SaveLogin" id="save">Save my login so you can remember me on my next visit.</label>
      </div>
      <div align="center" style="padding-top:20px">
        <input class="button" type="submit" name="Submit" value="Submit">
        <input class="button" type="reset" name="Clear" value="Clear">
        <input class="button" type="submit" name="Recognize" value="Remember me?">
      </div>
    

    Error:

                org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.id: UserID (tried for 100 second(s) with 500 milliseconds interval)
                at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
                at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
                at seleniumPages.Page_LoginMyApplication.enterApplicationCerdentials(Page_LoginMyApplication.java:51)
                at stepDefinitions.StepDefs_DataDrivenLogin.i_login_with_credentials_and(StepDefs_DataDrivenLogin.java:23)
                at ?.I login with credentials "tomsmith" and "***************"(resources/features/DataDrivenLogin.feature:7)
            Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"UserID"}
              (Session info: chrome=73.0.3683.103)
              (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
            Command duration or timeout: 0 milliseconds
            For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
            Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
            System info: host: 'AP01154W8N', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_191'
            Driver info: org.openqa.selenium.chrome.ChromeDriver
            Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.46.628402 (536cd7adbad73a..., userDataDir: C:\Users\sinham0\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:51153}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.103, webStorageEnabled: true}
            Session ID: 972c9f27cf1a2e9a5905ba48b3a11e65
            *** Element info: {Using=id, value=UserID}
                at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
                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:158)
                at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
                at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
                at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
                at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)
                at org.openqa.selenium.By$ById.findElement(By.java:188)
                at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
                at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
                at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
                at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:641)
                at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:638)
                at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
                at seleniumPages.Page_LoginMyApplication.enterApplicationCerdentials(Page_LoginMyApplication.java:51)
                at stepDefinitions.StepDefs_DataDrivenLogin.i_login_with_credentials_and(StepDefs_DataDrivenLogin.java:23)
                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 cucumber.runtime.Utils$1.call(Utils.java:31)
                at cucumber.runtime.Timeout.timeout(Timeout.java:16)
                at cucumber.runtime.Utils.invoke(Utils.java:25)
                at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)
                at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)
                at cucumber.api.TestStep.executeStep(TestStep.java:102)
                at cucumber.api.TestStep.run(TestStep.java:83)
                at cucumber.api.TestCase.run(TestCase.java:58)
                at cucumber.runner.Runner.runPickle(Runner.java:80)
                at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
                at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
                at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
                at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
                at cucumber.api.junit.Cucumber.runChild(Cucumber.java:118)
                at cucumber.api.junit.Cucumber.runChild(Cucumber.java:56)
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    


  • UserID field is not a clickable field it's a input field so i will suggest you to use this

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("UserID")));  
    

    Second one is why you have define the WebElement two times there is no use of it, change your code like this, may this help:-

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("UserID"))).sendKeys(userName);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Password"))).sendKeys(password);
    captureScreen();  
    

    If the

    <table>
    

    tag is inside the frame tag then try this:-

    • if you know the frame name-

      driver.switchTo().frame("XYZ");

    • If you don't know frame name or number of frames on page-

      int size = driver.findElements(By.tagName("iframe")).size(); it will give you the number of frame on your page then you can directly switch to your frame by index value-

      driver.switchTo().frame(i); where i=1,2,3.....



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2