0

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

  • 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. – Bill Hileman Sep 20 '18 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 Sep 20 '18 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. – Bill Hileman Sep 20 '18 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. – Bill Hileman Sep 20 '18 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 Sep 20 '18 at 18:28
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']")
  • 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 Sep 20 '18 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 Sep 21 '18 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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