If it is the only iframe
starting with frame-preview locator you can use partial css locator (or xpath - up to you) to explicity state the frame you want to change to:
List<WebElement> iframes = driver.findElements(By.cssSelector("iframe[id^='frame-preview']");
driver.switchTo().frame(iframes.get(INDEX_OF_IFRAME_TO_USE));
Then try some more explicit selector for the modal-content:
WebElement modalContent = driver.findElement(By.cssSelector("div[data-rec-id='FloatingPanelComponent-modalContainer] div[class='modal-content']");
If this results in NoSuchElementException
you should probably introduce some timeout. Test it by placing a breakpoint
at the WebElement modalContent
line. If waiting resolves your issue, introduce an ExplicitWait
, like this:
WebDriverWait wait = new WebDriverWait(webDriver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[data-rec-id='FloatingPanelComponent-modalContainer] div[class='modal-content']")));