New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching Iframes #194

Closed
cmiles74 opened this Issue Mar 8, 2013 · 6 comments

Comments

Projects
None yet
3 participants
@cmiles74

cmiles74 commented Mar 8, 2013

It could be I am doing something stupid, but I can't get GD to switch Iframes. My code works with CasperJS, but I can't get it working through Selenium and GD. When I attempt to switch to the Iframe, I get a stack trace from GD claiming the NoSuchFrame.

driver.get("http://localhost:51982/");
driver.findElement(By.id("addContextLink")).click();

List<WebElement> elements = driver.findElements(By.tagName("iframe"));
for(WebElement webElement : elements) {
    logger.info("  Iframe: " + webElement + ", " + webElement.getAttribute("id"));
    driver.switchTo().frame(webElement);
}

The error I'm seeing is...

PhantomJS is launching GhostDriver...
Ghost Driver running on port 20595
16:07:20,406  INFO ToDoHomePageTest:59 - Modal: [[PhantomJSDriver: phantomjs on LINUX (2a1f7dc0-8834-11e2-bb1b-d3ca27011056)] -> class name: wicket_modal], _wicket_window_3
16:07:20,461  INFO ToDoHomePageTest:63 -   Iframe: [[PhantomJSDriver: phantomjs on LINUX (2a1f7dc0-8834-11e2-bb1b-d3ca27011056)] -> tag name: iframe], _wicket_window_3
Error => {
  "message": "Error Message => 'Unable to switch to frame'\n caused by Request => {\"headers\":{\"Accept\":\"application/json, image/png\",\"Connection\":\"Keep-Alive\",\"Content-Length\":\"39\",\"Content-Type\":\"application/json; charset=utf-8\",\"Host\":\"localhost:20595\"},\"httpVersion\":\"1.1\",\"method\":\"POST\",\"post\":\"{\\\"id\\\":{\\\"ELEMENT\\\":\\\":wdc:1362776840251\\\"}}\",\"url\":\"/frame\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"frame\",\"directory\":\"/\",\"path\":\"/frame\",\"relative\":\"/frame\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/frame\",\"queryKey\":{},\"chunks\":[\"frame\"]},\"urlOriginal\":\"/session/2a1f7dc0-8834-11e2-bb1b-d3ca27011056/frame\"}",
  "name": "NoSuchFrame",
  "errorStatusCode": 8,
  "errorSessionId": "2a1f7dc0-8834-11e2-bb1b-d3ca27011056",
  "errorClassName": "SessionReqHand",
  "errorScreenshot": "...",
  "line": 577,
  "sourceId": 139993807908480,
  "sourceURL": ":/ghostdriver/request_handlers/session_request_handler.js",
  "stack": "NoSuchFrame: Error Message => 'Unable to switch to frame'\n caused by Request => {\"headers\":{\"Accept\":\"application/json, image/png\",\"Connection\":\"Keep-Alive\",\"Content-Length\":\"39\",\"Content-Type\":\"application/json; charset=utf-8\",\"Host\":\"localhost:20595\"},\"httpVersion\":\"1.1\",\"method\":\"POST\",\"post\":\"{\\\"id\\\":{\\\"ELEMENT\\\":\\\":wdc:1362776840251\\\"}}\",\"url\":\"/frame\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"frame\",\"directory\":\"/\",\"path\":\"/frame\",\"relative\":\"/frame\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/frame\",\"queryKey\":{},\"chunks\":[\"frame\"]},\"urlOriginal\":\"/session/2a1f7dc0-8834-11e2-bb1b-d3ca27011056/frame\"}\n    at :/ghostdriver/request_handlers/session_request_handler.js:577\n    at :/ghostdriver/request_handlers/session_request_handler.js:151\n    at :/ghostdriver/request_handlers/request_handler.js:61\n    at :/ghostdriver/request_handlers/router_request_handler.js:79",
  "stackArray": [
    {
      "sourceURL": ":/ghostdriver/request_handlers/session_request_handler.js",
      "line": 577
    },
    {
      "sourceURL": ":/ghostdriver/request_handlers/session_request_handler.js",
      "line": 151
    },
    {
      "sourceURL": ":/ghostdriver/request_handlers/request_handler.js",
      "line": 61
    },
    {
      "sourceURL": ":/ghostdriver/request_handlers/router_request_handler.js",
      "line": 79
    }
  ]
}
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.057 sec <<< FAILURE!
textAddContext(com.windsorsolutions.todos.integration.service.ToDoHomePageTest)  Time elapsed: 1.652 sec  <<< ERROR!
org.openqa.selenium.NoSuchFrameException: Error Message => 'Unable to switch to frame'
 caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"39","Content-Type":"application/json; charset=utf-8","Host":"localhost:20595"},"httpVersion":"1.1","method":"POST","post":"{\"id\":{\"ELEMENT\":\":wdc:1362776840251\"}}","url":"/frame","urlParsed":{"anchor":"","query":"","file":"frame","directory":"/","path":"/frame","relative":"/frame","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/frame","queryKey":{},"chunks":["frame"]},"urlOriginal":"/session/2a1f7dc0-8834-11e2-bb1b-d3ca27011056/frame"}
Command duration or timeout: 102 milliseconds
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-25-generic', java.version: '1.7.0_15'
Session ID: 2a1f7dc0-8834-11e2-bb1b-d3ca27011056
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=false, locationContextEnabled=false, version=phantomjs-1.9.0+ghostdriver-1.0.2, databaseEnabled=false, cssSelectorsEnabled=true, handlesAlerts=false, browserConnectionEnabled=false, proxy={proxyType=direct}, webStorageEnabled=false, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:533)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:798)
    at com.windsorsolutions.todos.integration.service.ToDoHomePageTest.textAddContext(ToDoHomePageTest.java:72)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-25-generic', java.version: '1.7.0_15'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:125)
    ... 34 more
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Error Message => 'Unable to switch to frame'
 caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"39","Content-Type":"application/json; charset=utf-8","Host":"localhost:20595"},"httpVersion":"1.1","method":"POST","post":"{\"id\":{\"ELEMENT\":\":wdc:1362776840251\"}}","url":"/frame","urlParsed":{"anchor":"","query":"","file":"frame","directory":"/","path":"/frame","relative":"/frame","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/frame","queryKey":{},"chunks":["frame"]},"urlOriginal":"/session/2a1f7dc0-8834-11e2-bb1b-d3ca27011056/frame"}
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-25-generic', java.version: '1.7.0_15'
Driver info: driver.version: unknown
@detro

This comment has been minimized.

Owner

detro commented Mar 10, 2013

I'd love to investigate but I need to see the HTML/JS code your test is testing to understand what might be going wrong.

@cmiles74

This comment has been minimized.

cmiles74 commented Mar 11, 2013

Okay, the application is running over here...

http://sophia.nervestaple.com:8080/

The project that generates this site is also on Github.

https://github.com/cmiles74/wicket-todos

You can take a look at my Selenium tests, the CasperJS tests are also available.

Thank you for taking a look at this.

@detro

This comment has been minimized.

Owner

detro commented Mar 17, 2013

Bad/Good news: I can reproduce.

Worse, it's something wrong with Qt and the detection of name/id of iframes :(

@detro

This comment has been minimized.

Owner

detro commented Mar 17, 2013

I think I found a strategy that should work around this issue.

@ghost ghost assigned detro Mar 18, 2013

@detro detro closed this in 993b4d7 Mar 18, 2013

@cmiles74

This comment has been minimized.

cmiles74 commented Mar 19, 2013

This has fixed my issue, thank you. 👍

@parikshithkulkarni

This comment has been minimized.

parikshithkulkarni commented Jan 12, 2018

what was the fix here?

I'm facing this issue,

NoSuchFrameError: {"errorMessage":"Unable to switch to frame","request":{"headers":{"Accept":"application/json; charset=utf-8","Connection":"close","Content-Length":"20","Content-Type":"application/json;charset=UTF-8","Host":"localhost:4444"},"httpVersion":"1.1","method":"POST","post":"{"id":"modalIFrame"}","url":"/frame","urlParsed":{"anchor":"","query":"","file":"frame","directory":"/","path":"/frame","relative":"/frame","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/frame","queryKey":{},"chunks":["frame"]},"urlOriginal":"/session/e2686380-f7db-11e7-805d-9d1f88fbd6aa/frame"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment