<'WebDriver'>. SwitchTo (). Frame (<'frameId'>) does not work with Chrome driver

You must access the elements inside the modal iframe.

Below code works fine for FireFox driver, not 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 the Chrome driver support switchTo.frame (<'frameId'>)?

Error using Chrome driver -

org.openqa.selenium.WebDriverException: Unknown command. Parameters: ActivateTab, CaptureEntirePage, CloseTab, DeleteCookie, ...

Duration of the command or timeout: 220 milliseconds Assembly information: version: '2.25.0', version: '17482', time: '2012-07-18 22:18:01' System information: os.name: "Windows 7 ", os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_05' Driver information: 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.Web Remote .openqa.selenium.remote.RemoteWebElement.execute (RemoteWebElement.java:244) at org.openqa.selenium.remote.RemoteWebElement.sendKeys (RemoteWebElement.java:87) at com.shn.services.Office365.ilearePoint : 173) at com.shn.test.RunOffice365Test.testSharePointUploadAndDeleteFile (RunOffice365Test.java:55) at org.apache.maven.surefire.testng.TestNGExecutor.run (TestNGExecutor.java:est.estestiteTure.Test.Test.Test.Turn.Test.Turn.Turn.Turn.Turn.Turn.Test.Turn.Test.jt .execute (TestNGXmlTestSuite.java:92) on org.apache.maven.surefire.Surefire.run (Surefire.java:180) on org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess (SurefireBooter.java50) org.apache.maven.surefire.booter.SurefireBooter.main (SurefireBooter.java:1021)

+4
source share
4 answers

The question was neither with chromeDriver, nor with selenium. Both were in the latest versions.

chromeDriver - 23.0.1240.0

Selenium - 2.25.0

The problem was in the Chrome browser.

My browser worked on ver. 12.0.742.112. Automatic updates failed due to -

Server update unavailable (error: 7)

I had to uninstall and reinstall the browser in order to get it to the latest version. 21.0.1180.89 m.

Now the problem is fixed, and I can switch between frames.

+3
source

ChromeDriver supports switchTo because it implements the WebDriver interface. This works great for me.

You should do it as follows:

 driver.switchTo().frame(driver.findElement(By.id("frameId"))); //do your stuff driver.switchTo().defaultContent(); 
+4
source

It seems the problem is not in the iframe. The list of errors includes org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:87) at . Therefore, I assume that another part of your code will lead to the application. to fail.

+1
source

This is my implementation of switching to a frame for all browsers, because switching to a frame by ID or name does not work for Chrome (with the latest versions)

  • using Xpath (more elegant / readable code):
 /** * This switch to frame method improves standard way to switching to frame * ( driver.switchTo().{@linkplain org.openqa.selenium.WebDriver.TargetLocator#frame(String) frame(String nameOrId)} ) * because Chrome browser has problem with this method. <br/> * * Bug: http://code.google.com/p/chromedriver/issues/detail?id=107 * @param frameIdOrName the id or name of the &lt;frame&gt; or &lt;iframe&gt; element * @return This driver focused on the given frame. */ public WebDriver switchToFrameByIdOrName(String frameNameOrId) { if (driver instanceof ChromeDriver) { String frameElementXpath = String.format("//frame[@name='%1$s' or @id='%1$s']", frameNameOrId); WebElement f = driver.findElement(By.xpath(frameElementXpath)); return driver.switchTo().frame(f); } return driver.switchTo().frame(frameNameOrId); } 

or

  • using CSS selectors (because the CSS selector should be a faster way to find elements. For more information, see Choosing WebDriver Locators :
 public WebDriver switchToFrameByIdOrName(String frameIdOrName) { if (!(driver instanceof ChromeDriver)) { return driver.switchTo().frame(frameIdOrName); } WebElement frame = null; try { frame = driver.findElement(By.cssSelector("frame[id='" + frameIdOrName + "']")); } catch (NoSuchElementException e) { /* It ok for the moment */ } if (frame == null) { try { frame = driver.findElement(By.cssSelector("frame[name='" + frameIdOrName + "']")); } catch (NoSuchElementException e) { log.severe(String.format("CORE > switchToFrameByIdOrName() error: Frame with name or id '%s' not found.", frameIdOrName)); } } return driver.switchTo().frame(element); } 

I use:

 Selenium 2.37.1 Session info: chrome=31.0.1650.57) Driver info: chromedriver=2.7.236900,platform=Windows NT 6.1 SP1 x86_64 
+1
source

Source: https://habr.com/ru/post/1434767/


All Articles