Need to access elements inside a modal iframe.
Below code works perfectly fine for FireFox driver while fails for Chrome -
String frameId = null;
List<WebElement> frameSet = driver.findElements(By.tagName("iframe"));
for (WebElement frameName : frameSet){
if(!(frameName.getAttribute("id").isEmpty()) && (frameName.getAttribute("id").contains("DlgFrame"))){
frameId = frameName.getAttribute("id");
}
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Logger.info("Switch to Frame - "+frameId);
driver.switchTo().frame(driver.findElement(By.id(frameId)));
Does Chrome driver support switchTo.frame(<'frameId'>)?
Error while using Chrome Driver -
org.openqa.selenium.WebDriverException: Unknown command. Options: ActivateTab, CaptureEntirePage, CloseTab, DeleteCookie, ...
Command duration or timeout: 220 milliseconds Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 22:18:01' System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_05' Driver info: driver.version: RemoteWebDriver Session ID: cbde65cb0394ee0434b3bb528918ce40 at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:498) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:244) at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:87) at com.shn.services.Office365.sharePointUploadFile(Office365.java:173) at com.shn.test.RunOffice365Test.testSharePointUploadAndDeleteFile(RunOffice365Test.java:55) at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:74) at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92) at org.apache.maven.surefire.Surefire.run(Surefire.java:180) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
I don't know if this will help anyone, but I was having a similar issue polling frames and this is what the solution was for me.
Switch to DefaultContent():
_driver.SwitchTo().DefaultContent();
Get the frames:
IWebElement iFrames = _driver.FindElements(By.XPath("//iframe"));
Poll through the frames, but only switch to it if "Displayed" is true:
foreach (var frame in iFrames)
{
if (!frame.Displayed)
continue;
_driver.SwitchTo().Frame(frame);
}
ChromeDriver supports switchTo since it implements the WebDriver Interface. It works fine for me.
You have to do it like this:
driver.switchTo().frame(driver.findElement(By.id("frameId")));
//do your stuff
driver.switchTo().defaultContent();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With