0

I am trying to run my selenium script on Browser stack , while running script facing problem while switching to frame. sometime it does but sometime not. Is there any permanent solution for it.

driver.switchTo().defaultContent();
List iframeElements = driver.findElements(By.tagName("iframe")); 
System.out.println("The total number of iframes are " + iframeElements.size()); 
WebElement frame = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(frame); Thread.sleep(5000);
driver.switchTo().defaultContent();
2
  • Please add the code you tried for switching to the frame and the html snippet of the frame.The permanent solution could be to wait for the frame to be available and after to switch to it, on BS the execution is slightly slower. Commented Jul 13, 2017 at 13:10
  • driver.switchTo().defaultContent(); List<WebElement> iframeElements = driver.findElements(By.tagName("iframe")); System.out.println("The total number of iframes are " + iframeElements.size()); WebElement frame = driver.findElement(By.tagName("iframe")); driver.switchTo().frame(frame); Thread.sleep(5000); driver.switchTo().defaultContent(); Commented Jul 13, 2017 at 13:25

1 Answer 1

0

You can wait until frame to be available as given below. It may help you.

WebElement frame = driver.findElement(By.tagName("iframe"));
WebDriverWait wait = new WebDriverWait(driver, 90);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frame));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.