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

Error when `switch_to.parent_frame` in PhantomJS and Safari #1737

Closed
jasonkarns opened this Issue Mar 3, 2016 · 11 comments

Comments

Projects
None yet
5 participants
@jasonkarns

jasonkarns commented Mar 3, 2016

Expected Behavior -

switch_to.parent_frame should switch to parent frame context

Actual Behavior -

#<Selenium::WebDriver::Error::WebDriverError: unexpected response, code=405, content-type="text/plain"
Invalid Command Method - {"headers":{"Accept":"application/json","Accept-Encoding":"gzip;q=1.0,deflate;q=0.6,identity;q=0.3","Connection":"close","Content-Length":"2","Content-Type":"application/x-www-form-urlencoded","Host":"127.0.0.1:8910","User-Agent":"Ruby"},"httpVersion":"1.1","method":"POST","post":"{}","postRaw":"{}","url":"/frame/parent","urlParsed":{"anchor":"","query":"","file":"parent","directory":"/frame/","path":"/frame/parent","relative":"/frame/parent","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/frame/parent","queryKey":{},"chunks":["frame","parent"]},"urlOriginal":"/session/ffde7330-e150-11e5-93a8-5ded1f31d492/frame/parent"}>

Steps to reproduce -

@page.find_elements(:tag_name, "iframe").each do |iframe|
  @page.switch_to.frame(iframe)
  # eval some JS here
  @page.switch_to.parent_frame
rescue => e
  # error caught here
  @page.switch_to.default_content
end

Using selenium-webdriver ruby gem. Issue manifests under versions 2.52.0 and 2.46.2 (I was originally running 2.46.2, upgraded to 2.52.0 to try and resolve issue but still occurring)

Error occurs on PhantomJS 2.1.1. No errors with Firefox or Chrome. However Safari (latest driver: 2.48) reports a similar error:

#<Selenium::WebDriver::Error::UnknownError: Unknown command: switchToParentFrame>

FWIW, I get the exact same errors for PhantomJS/Safari when running under watir-webdriver 0.8.0, while watir+Firefox and watir+Chrome work fine.

On the other hand, Capybara works just fine on PhantomJS and Safari.

@lukeis

This comment has been minimized.

Show comment
Hide comment
@lukeis

lukeis Mar 3, 2016

Member

You'll need to log a bug with the phantomjs (ghostdriver) project, it is not maintained here (or at all really).

I'll leave this open for Safari.

Member

lukeis commented Mar 3, 2016

You'll need to log a bug with the phantomjs (ghostdriver) project, it is not maintained here (or at all really).

I'll leave this open for Safari.

@lukeis lukeis added the D-safari label Mar 3, 2016

@jasonkarns

This comment has been minimized.

Show comment
Hide comment
@jasonkarns

jasonkarns Mar 3, 2016

How are we sure that it's those particular drivers? As noted, Capybara
works fine with Safari and Phantom, whereas watir (which uses selenium
under the hood) fails.

The only commonality between the failures is selenium-webdriver.

On Thu, Mar 3, 2016 at 11:04 AM, Luke Inman-Semerau <
notifications@github.com> wrote:

You'll need to log a bug with the phantomjs (ghostdriver) project, it is
not maintained here (or at all really).

I'll leave this open for Safari.


Reply to this email directly or view it on GitHub
#1737 (comment)
.

jasonkarns commented Mar 3, 2016

How are we sure that it's those particular drivers? As noted, Capybara
works fine with Safari and Phantom, whereas watir (which uses selenium
under the hood) fails.

The only commonality between the failures is selenium-webdriver.

On Thu, Mar 3, 2016 at 11:04 AM, Luke Inman-Semerau <
notifications@github.com> wrote:

You'll need to log a bug with the phantomjs (ghostdriver) project, it is
not maintained here (or at all really).

I'll leave this open for Safari.


Reply to this email directly or view it on GitHub
#1737 (comment)
.

@titusfortner

This comment has been minimized.

Show comment
Hide comment
@titusfortner

titusfortner Mar 4, 2016

Member

@jasonkarns:
Watir doesn't switch frames directly, it does that for you when you are looking for elements. That gets a little more complicated if you are trying to do javascript only things inside a different browser context, but this would work:

browser.iframes.each do |iframe|
  iframe.element.exist?
  # eval some JS here
end

Phantom & JS do not implement the parent endpoint, so there is no way for them to support that feature in Selenium or Capybara.

Member

titusfortner commented Mar 4, 2016

@jasonkarns:
Watir doesn't switch frames directly, it does that for you when you are looking for elements. That gets a little more complicated if you are trying to do javascript only things inside a different browser context, but this would work:

browser.iframes.each do |iframe|
  iframe.element.exist?
  # eval some JS here
end

Phantom & JS do not implement the parent endpoint, so there is no way for them to support that feature in Selenium or Capybara.

@jasonkarns

This comment has been minimized.

Show comment
Hide comment
@jasonkarns

jasonkarns Mar 4, 2016

This is for a gem so it needs to support all three of selenium, watir, and capybara. Executing and evaling JS in main and all nested frames are the only browser actions that I need to perform internally to the gem and we aren't intending to expose any common api to users. So the approach I've taken is to apply wrapping adapters to the provided driver (regardless which driver it actually is) that implement just the bare minimum of methods that we need internally (execute_script, evaluate_script, and frame navigation). At the moment the driver is wrapped, we inspect to see which methods the driver already supports (mostly with respond_to?) and polyfill accordingly. The adapters themselves are delegators (i.e. DelegateClass, though we're using dumb-delegator) so if underlying driver already supports the methods, then we don't wrap them.

So while watir's implicit frame navigation is great for apps using it, it doesn't really help in our situation directly. For our within_frame wrapper on Watir, we just grab the underlying selenium driver and operate directly on that. (And when given a Watir iframe node, we grab the backing #wd element.)

Phantom & JS do not implement the parent endpoint, so there is no way for them to support that feature in Selenium or Capybara.

This doesn't line up with the fact that both Capybara+Safari and Capybara+PhantomJS work fine for us. It's only safari/phantom under selenium/watir. (Though really, watir isn't involved, since as I noted, we interact with watir's underlying selenium object.)

edit

Capybara + Safari and Capybara + Phantom both work using selenium under the hood:

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => $browser)
end

jasonkarns commented Mar 4, 2016

This is for a gem so it needs to support all three of selenium, watir, and capybara. Executing and evaling JS in main and all nested frames are the only browser actions that I need to perform internally to the gem and we aren't intending to expose any common api to users. So the approach I've taken is to apply wrapping adapters to the provided driver (regardless which driver it actually is) that implement just the bare minimum of methods that we need internally (execute_script, evaluate_script, and frame navigation). At the moment the driver is wrapped, we inspect to see which methods the driver already supports (mostly with respond_to?) and polyfill accordingly. The adapters themselves are delegators (i.e. DelegateClass, though we're using dumb-delegator) so if underlying driver already supports the methods, then we don't wrap them.

So while watir's implicit frame navigation is great for apps using it, it doesn't really help in our situation directly. For our within_frame wrapper on Watir, we just grab the underlying selenium driver and operate directly on that. (And when given a Watir iframe node, we grab the backing #wd element.)

Phantom & JS do not implement the parent endpoint, so there is no way for them to support that feature in Selenium or Capybara.

This doesn't line up with the fact that both Capybara+Safari and Capybara+PhantomJS work fine for us. It's only safari/phantom under selenium/watir. (Though really, watir isn't involved, since as I noted, we interact with watir's underlying selenium object.)

edit

Capybara + Safari and Capybara + Phantom both work using selenium under the hood:

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => $browser)
end
@titusfortner

This comment has been minimized.

Show comment
Hide comment
@titusfortner

titusfortner Mar 4, 2016

Member

Error occurs on PhantomJS 2.1.1. No errors with Firefox or Chrome. However Safari (latest driver: 2.48) reports a similar error

This makes sense because phantomjs & safari do not support switch_to.parent_frame but Firefox & Chrome do.

Capybara works fine with Safari and Phantom

This surprises me; what is the code you are using for Capybara?
@page.switch_to.parent_frame ?
What is @page an instance of?
If you do $DEBUG = true you can see in stdout what commands are actually getting passed to the driver, and what the responses are.

Member

titusfortner commented Mar 4, 2016

Error occurs on PhantomJS 2.1.1. No errors with Firefox or Chrome. However Safari (latest driver: 2.48) reports a similar error

This makes sense because phantomjs & safari do not support switch_to.parent_frame but Firefox & Chrome do.

Capybara works fine with Safari and Phantom

This surprises me; what is the code you are using for Capybara?
@page.switch_to.parent_frame ?
What is @page an instance of?
If you do $DEBUG = true you can see in stdout what commands are actually getting passed to the driver, and what the responses are.

@franzejr

This comment has been minimized.

Show comment
Hide comment
@franzejr

franzejr Mar 26, 2016

I'm having the same problem on Safari. I have an iframe, when I go to my parentFrame, I got:

Selenium::WebDriver::Error::UnknownError:
       Unknown command: switchToParentFrame (WARNING: The server did not provide any stacktrace information)
       Command duration or timeout: 3 milliseconds

franzejr commented Mar 26, 2016

I'm having the same problem on Safari. I have an iframe, when I go to my parentFrame, I got:

Selenium::WebDriver::Error::UnknownError:
       Unknown command: switchToParentFrame (WARNING: The server did not provide any stacktrace information)
       Command duration or timeout: 3 milliseconds
@Szarko

This comment has been minimized.

Show comment
Hide comment
@Szarko

Szarko Jun 14, 2016

Any status update on this issue? I am also experiencing:
Selenium::WebDriver::Error::UnknownError:
Unknown command: switchToParentFrame

This occurs when loading a page with an iFrame and trying to navigate through it's form fields.

Szarko commented Jun 14, 2016

Any status update on this issue? I am also experiencing:
Selenium::WebDriver::Error::UnknownError:
Unknown command: switchToParentFrame

This occurs when loading a page with an iFrame and trying to navigate through it's form fields.

@lukeis

This comment has been minimized.

Show comment
Hide comment
@lukeis

lukeis Jun 14, 2016

Member

there's no intention on updating SeleniumHQ's version of a Safari Driver.

Apple has just announced that in macOS 10.12 (Sierra) there will be a safaridriver bundled in the OS itself. Obviously this is only available as a developer preview right now, but because of this work being done by Apple themselves we aren't going to work on the SafariDriver extension.

Member

lukeis commented Jun 14, 2016

there's no intention on updating SeleniumHQ's version of a Safari Driver.

Apple has just announced that in macOS 10.12 (Sierra) there will be a safaridriver bundled in the OS itself. Obviously this is only available as a developer preview right now, but because of this work being done by Apple themselves we aren't going to work on the SafariDriver extension.

@Szarko

This comment has been minimized.

Show comment
Hide comment
@Szarko

Szarko Jun 14, 2016

Is there any work around for this issue that you know of? And thank you for your prompt response, appreciate it.

Szarko commented Jun 14, 2016

Is there any work around for this issue that you know of? And thank you for your prompt response, appreciate it.

@lukeis

This comment has been minimized.

Show comment
Hide comment
@lukeis

lukeis Jun 14, 2016

Member

switchTo defaultContent? then switch back down the frameset?

Member

lukeis commented Jun 14, 2016

switchTo defaultContent? then switch back down the frameset?

@lukeis

This comment has been minimized.

Show comment
Hide comment
@lukeis

lukeis Sep 23, 2016

Member

With the release of Safari 10, Apple now offers official support WebDriver. Because of this, the Selenium project no supports the legacy implementation from 2.x.

Users are advised to switch to Apple's driver and file bugs at
https://bugreport.apple.com/

We are no longer tracking issues for Selenium's SafariDriver and thus closing this issue.

Member

lukeis commented Sep 23, 2016

With the release of Safari 10, Apple now offers official support WebDriver. Because of this, the Selenium project no supports the legacy implementation from 2.x.

Users are advised to switch to Apple's driver and file bugs at
https://bugreport.apple.com/

We are no longer tracking issues for Selenium's SafariDriver and thus closing this issue.

@lukeis lukeis closed this Sep 23, 2016

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