1

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");
        }
       }

Error (Console log):

    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
8
  • Since you are searching by.id it makes no sense why the log would report it as an error with css selector. try driver.findElement(By.xpath("//*[@id='text-input-what']")).sendKeys("Selenium"); which worked fine for me. Commented Sep 20, 2018 at 17:38
  • Are you saying you were successful by using xpath in my code ? I tried using xpath("//*[@id='text-input-what']")) and (By.xpath("//*[@name='q']")) but no luck. My code works fine with chrome. its only with IE11
    – paulso
    Commented Sep 20, 2018 at 18:14
  • Yes, I did use Chrome and did not proceed on the assumption that it might be browser related. It's still highly-suspicious that it's reporting a CSS error when you're not attempting, at least in the code you're showing, to locate by CSS. Have you been able to get anything at all to run in the IE browser, to eliminate the possibility that's it's just a browser configuration/instantiation issue? Personally I avoid IE like the plague but I realize that might not be an option for you. Commented Sep 20, 2018 at 18:18
  • FWIW you might consider moving the implicit wait line to be the first line after the driver is created, before the get command, at least. Commented Sep 20, 2018 at 18:20
  • So are i am only successful in opening the page in IE and maximizing it and unsuccessful when tried with moving the implicit wait with error "Unable to find element with xpath == //*[@id='text-input-what']". Tried with "Thread.sleep(5000)" no luck
    – paulso
    Commented Sep 20, 2018 at 18:28

2 Answers 2

0

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']")
2
  • Thanks for your comment , whether I keep the implicitlyWait timer or not and after using all the selectors I am still getting the error "Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with css selector"
    – paulso
    Commented Sep 20, 2018 at 19:47
  • 1
    @paulso You need to set properties on the IE Browser so Selenium can utilize the browser. Are you successful with other elements and it’s just this one? If it’s just this one then please place the HTML for the element in you question.
    – mutt
    Commented Sep 21, 2018 at 10:45
0

However, Internet Explorer is now going to be deprecated soon, so trying to answer using Edgedriver.

import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.edge.EdgeDriver;  

public class IndeedJobSearch {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // Gives dynamic path till project level
        String path = System.getProperty("user.dir");
        System.setProperty("webdriver.edge.driver", path + "/drivers/msedgedriver");
        // Create Internet explorer driver to driver the browser
        WebDriver driver = new EdgeDriver();
        // Maximize the window server.
        driver.manage().window().maximize();
        // Open Indeed home page
        driver.get("https://www.indeed.co.uk/");
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        // Find What field and enter Selenium  
//     driver.findElement(By.id("text-input-what")).sendKeys("Selenium");  
//     driver.findElement(By.cssSelector("input[id=text-input-what]")).sendKeys("Selenium");  
//     driver.findElement(By.cssSelector("input[id^=text-input]")).sendKeys("Selenium");  
//     driver.findElement(By.cssSelector("input[class='icl-TextInput-control icl-TextInput-control--withIconRight']")).sendKeys("Selenium");  
//     driver.findElement(By.cssSelector("input.icl-TextInput-control")).sendKeys("Selenium");  
        driver.findElement(
                By.cssSelector("div>input[class='icl-TextInput-control icl-TextInput-control--withIconRight']"))
                .sendKeys("Selenium");  

    }
}

In the above code, I have posted answers on different ways to use CSS selectors for finding elements.

Your Answer

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

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