Selenium WebDriver + JUnit. It doesn't see the items that Selenium IDE detects

  • Good day to all! I switched from Selenium IDE to WebDriver + JUnit and I have the following problem: locators, which Selenium IDE saw before, does not see WebDriver. For example:

    IDE command

    waitForVisible -> xpath =. // * [@ id = 'listContainer']

    The element is being discovered.

    Command from JUnit:

    1.Assert.assertTrue ("Element isn't exist",! Driver.findElements (By.xpath (".//* [@ id = 'listContainer']")). IsEmpty ());

    Error: Element isn't exist


    If you try to find by id

    2.Assert.assertTrue (driver.findElement ( ("listContainer")). IsDisplayed ());
    Error: NoSuchElementException: Unable to locate element ...


    The timer is on and the elements on the page are loaded.

    Full code below:

    public class Simpletest {
    String baseUrl;
    WebDriver driver;
        public void testSetup () {
            driver = new ChromeDriver ();
            baseUrl = "";
        public void testShutDown () {
            driver.close ();
        public void shouldHaveTestAboutProfileSettings () {
            driver.get (baseUrl + "/SIMULATOR/index.html");
            wait (2);
        // Assert.assertTrue ("Element isn't exist",! Driver.findElements (By.xpath (".//* [@ id = 'listContainer']")). IsEmpty ());
           Assert.assertTrue (driver.findElement ( ("listContainer")). IsDisplayed ());
      public void wait (int seconds) {
      try {
          Thread.sleep (seconds * 1000);
      } catch (InterruptedException e) {
          e.printStackTrace ();



    Ideally, I need to check for the presence of a clickItem with id = 0

  • I figured out what the problem was. Indeed, the element I was looking for associated frame, and the webdriver was looking for elements in the root of the html page. From this it turns out that the Selenium IDE sees at once the entire structure of the page and, accordingly, all the elements. This is probably why the problem did not arise before. As a result, this is solved by switching to the desired frame via the command:

    driver.switchTo (). Frame (driver.findElement ( ("here is the frame id")));

Log in to reply

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2