org.openqa.selenium.NoSuchElementException



  • here is my sript

    driver.findElement(By.xpath("//span[contains(text(),'Hotel Log')]")).click();
    
            Thread.sleep(10000L);
            driver.findElement(By.xpath("//button[@class='btn cta-button']")).click();
            driver.findElement(By.xpath("//input[@placeholder='Title (optional)']"))
                    .sendKeys("Test Post created by Prachi through Selenium");
            Thread.sleep(10000L);
            driver.findElement(By.xpath("//*[@class='form-control text-uppercase']")).sendKeys(Keys.TAB);
    
            driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/div[1]/div/textarea"))
                    .sendKeys("Description One through automation. Please ignore");
    
            WebElement uploadimage = driver.findElement(By.xpath("//button[contains(text(),'Upload Image')]"));
            uploadimage.sendKeys("C:\\Users\\ue\\Desktop\\Pic\\test.jpg");
    
            driver.findElement(By.xpath("//button[@class= 'btn cta-button right ']")).click();
            System.out.println("Test post created");
    

    However , below error I am getting suddenly.

    org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(text(),'Hotel Log')]"}
      (Session info: chrome=80.0.3987.87)
      (Driver info: chromedriver=79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 20.06 seconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
    System info: host: 'DESKTOP-DI09CAH', ip: '192.168.29.183', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_241'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities [{mobileEmulationEnabled=false, timeouts={implicit=0, pageLoad=300000, script=30000}, hasTouchScreen=false, platform=XP, acceptSslCerts=false, goog:chromeOptions={debuggerAddress=localhost:50685}, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=ignore, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}), userDataDir=C:\Users\ue\AppData\Local\Temp\scoped_dir13164_755023138}, takesHeapSnapshot=true, pageLoadStrategy=normal, strictFileInteractability=false, databaseEnabled=false, handlesAlerts=true, version=80.0.3987.87, browserConnectionEnabled=false, proxy={}, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
    Session ID: f96dd8bcdd79f9cf65d900e4f0e9b6b9
    


  • You can try implementing WebDriver wait for this -

    Webdriver driver;
    WebDriverWait wait = new WebDriverWait(driver, 100);
    element= wait.until(ExpectedConditions.elementToBeClickable(By.XPATH("//span[contains(text(),'Hotel Log')]")));
    


Suggested Topics

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