Reputation: 67
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 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.
Upvotes: 0
Views: 1135
Reputation: 193088
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();
You can find a detailed discussion on NoSuchElementException in:
Upvotes: 1