0

I want to create a Selenium test, where a modal dialog is used. If I want to use the element in the div I get the error message that the element cannot be found. I have also tried to switch to the active element, or to switch to the frame. If I make this I get the error, that the frame cannot be found.

This is the html code: enter image description here

This was my idea to switch to the modal:

driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[8]/div"));

And this is the error I got:

org.openqa.selenium.NoSuchFrameException: Unable to locate frame: 805833b6-6961-41e5-8bdf-3393a28e0ad9

In the end I want to press the button inside the modal. I hope someone can help me to reach this with a selenium java test.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
tobias
  • 63
  • 2
  • 8
  • What do you get from: `List buttons = driver.findElements(By.tagname("button")); for (WebElement button: buttons) { System.out.println(button.getText()); } WebElement modal = driver.findElement(By.className("modal-content")); driver.switchTo().frame(modal); List buttonsInModal = driver.findElements(By.tagname("button")); for (WebElement button: buttonsInModal) { System.out.println(button.getText()); }`? – pburgr Dec 22 '20 at 10:39

1 Answers1

1

This error message...

org.openqa.selenium.NoSuchFrameException: Unable to locate frame: 805833b6-6961-41e5-8bdf-3393a28e0ad9

...implies that the WebElement you have identified as an <iframe> isn't an <iframe> actually.

From the HTML markup it seems the element is within a Modal Dialog Box and there are two buttons in it. To click on the two buttons you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • To click on Weiter

    • cssSelector:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.btn-primary[ng-show^='firstStep.state.spaces.length']"))).click();
      
    • xpath:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn-primary' and text()='Weiter']"))).click();
      
  • To click on Abbrechen

    • cssSelector:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.btn-default[data-dismiss='modal']"))).click();
      
    • xpath:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn-default' and text()='Weiter']"))).click();
      

Reference

You can find a detailed discussion on NoSuchElementException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thanks this worked perfectly. Can you tell me also how to make this with a dropdown menu and with an input field ? – tobias Dec 22 '20 at 15:52
  • @tobias Sounds to be a completely different issue all together. Can you raise a new question as per your new requirement? Stackoverflow contributors will be happy to help you out. – undetected Selenium Dec 22 '20 at 15:54
  • ok I will open today a new question with new source code – tobias Dec 22 '20 at 16:22
  • https://stackoverflow.com/questions/65421606/selenium-find-select-and-input-in-dialog-modal this is my new question – tobias Dec 23 '20 at 09:04