Exception in thread "main" Unable to find element with css selector ==



  • When I am trying to run the below mentioned Selenium web driver code in IE 11 browser, I get below error:

        Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #text\-input\-what
    ```
    

    Code:

           package com.indeed.tests;
           import java.util.concurrent.TimeUnit;
           import org.openqa.selenium.By;
           import org.openqa.selenium.WebDriver;
           import org.openqa.selenium.ie.InternetExplorerDriver;
    
    public class IndeedJobSearch {
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    // Call the IE server to invoke IE browser
        System.setProperty("webdriver.ie.driver","C:\\Users\\paulso\\Desktop\\Testing\\Automation\\Selenium Automation\\IEDriverServer_Win32_3.14.0\\IEDriverServer.exe");  
     // Create Internet explorer driver to driver the browser
        WebDriver driver= new InternetExplorerDriver();
     // Maximize the window server.
        driver.manage().window().maximize();
     // Open Indeed home page
        driver.get("https://www.indeed.co.uk/");
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
     // Find What field and enter Selenium
        driver.findElement(By.id("text-input-what")).sendKeys("Selenium");
        }
       }
    
    
    <p><strong>Error (Console log):</strong></p>
    
    
    Started InternetExplorerDriver server (32-bit)
    3.14.0.0
    Listening on port 8609
    Only local connections are allowed
    Sep 20, 2018 11:31:15 AM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C
    Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #text\-input\-what
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    


  • driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

    This sets the implicit wait timer to 10 seconds. If the element is not present after those 10 seconds, then you will receive an ElementNotFound exception. You would also get the exception if your selector does not work. Test the selector in DevTool's DOM explorer's search.

    If the element is

    <input id="myInput">
    

    then the following selectors will work:

    • By.Id("myInput")
    • By.CssSelector("#myInput")
    • By.XPath("//*[@id='myInput']")


Suggested Topics

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