Skip to content
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

Unable to access web elements in a cross-origin (CROS) iframe on IOS mobile browser #2003

Closed
kieranjc opened this issue Mar 6, 2014 · 19 comments
Labels
Bug a problem that needs fixing Mobile Safari related to mobile Safari driver

Comments

@kieranjc
Copy link

kieranjc commented Mar 6, 2014

Hi,

(Issue ported from https://groups.google.com/forum/#!topic/appium-discuss/vIbhO_KljXc.)

I have starting using appium for testing of our mobile web app. Unfortunately it runs in an cross-origin iframe and Appium appears to have difficult accessing web elements in the iframe. I have setup a simple test page which contains a local iframe (same domain as parent) and a cross-origin iframe. Appium has no issue with accessing the local iframe content but fails when attempting to access elements within cross-origin iframe. Is this a known issue or does it sound like a bug. My WebDriver tests appear to work using chromedriver. I am new to Appium and was drawing to it as I would not need to change our internal testing framework which is Java/WebDriver based. I am stuck with this issues as our mobile app runs within Salesforce's environment so have no control over the use of iframes.

I see that switching to the cross-origin iframe seems to work, from the logs:

info: Entering new web frame: :wdc:1394013932388
info: Responding to client with success: {"status":0,"value":{"WINDOW":":wdc:1394013932388"},"sessionId":"539b787f-efa1-4060-b3fb-511549e5be1f"}

But when I attempt to access an element in the iframe I get the error "undefined' is not an object ", see below:

debug: Appium request initiated at /wd/hub/session/539b787f-efa1-4060-b3fb-511549e5be1f/element
debug: Request received with params: {"using":"xpath","value":"//table[@Class='snowrep']"}
info: [REMOTE] Wrapping script for frame :wdc:1394013932388
info: [REMOTE] Sending javascript command
debug: [REMOTE] Sending _rpc_forwardSocketData: message to remote debugger
debug: [REMOTE] Receiving data from remote debugger
debug: [REMOTE] Receiving data from remote debugger
debug: [REMOTE]
info: Responding to client with error: {"status":13,"value":{"message":"'undefined' is not an object (evaluating 'a.nodeType')","origValue":"'undefined' is not an object (evaluating 'a.nodeType')"},"sessionId":"539b787f-efa1-4060-b3fb-511549e5be1f"}

Regards,
Kieran

@bigfei
Copy link
Contributor

bigfei commented Mar 7, 2014

Since appium use the webdriver-atoms to do the testing, CROS cannot be simply supported. You'd either change the page or try to use the reverse proxy method on the testing server to bypass the CROS problem.

@mark-micallef
Copy link

Is this something that can be fixed/handled by Appium? We are currently experiencing the same issue and I am not sure reworking the app to avoid the CROS is feasible.

@jlipps
Copy link
Member

jlipps commented Mar 8, 2014

we'd have to dig into the remote webkit debug protocol to see if we can get special access to different-origin iframes. I'm skeptical though…

This'd be a research project I can't take on right now. @snevesbarros do you have any ideas?

@kieranjc
Copy link
Author

Guys, I would really appropriate anything you can do on this issue. I have reverted to using WebDriver and Chrome with a mobile user-agent to fool the web app into think its running on a mobile web browser. Its not ideal but at least its something.

@snevesbarros
Copy link
Contributor

I agree with @bigfei. Appium sends across the atoms (including some arguments) using the webkit protocol. I had a look at the documentation for the protocol but didn't find anything useful. I dont think there is a simple way to support cross domain requests other than fooling the iframe into thinking they are from the same domain (e.g. example here (#2)).

@jlipps jlipps closed this as completed Mar 24, 2014
@MarcusChen
Copy link

It would be good if this feature is added to Appium. I would think cross-origin iframe is common in eCommerce apps. For example I need to test credit card iframes from Chase PaymentTech. Thanks.

@jlipps
Copy link
Member

jlipps commented Aug 5, 2014

If someone can provide me a technique for this that works, I'll add it to the roadmap.

@ericzered
Copy link

Hello guys,
I'have the exact same probleme, still no solution or workaround, except the fake user-agent ?
Thanks

@mwang5
Copy link

mwang5 commented Sep 3, 2014

Same problem. and stuck. Some one can help with this? many thanks

@srihariinnamuri
Copy link

Same problem.Any solution for this issue

@chris-gunawardena
Copy link

Has anyone tried enabling Access-Control-Allow-Origin: * on the external server to fix this?

@bigfei
Copy link
Contributor

bigfei commented Mar 3, 2015

Sounds possible, I will do a test to verify this. @chris-gunawardena

@chris-gunawardena
Copy link

I tried adding "Access-Control-Allow-Origin: *" using Charles proxy but ran into the same issue.
Test case if anyone else wants to try: https://gist.github.com/chris-gunawardena/22b809d606b226e32270
Works fine if the iframe is in the same domain.

@chris-gunawardena
Copy link

In my case I was able to use charles proxy rewrite to inject a script to fill out the login form (which was in another domain) and submit it. Hope this helps.

@xiadw
Copy link

xiadw commented Oct 31, 2015

i have a question:
Why selenium in the pc safari running is good, about cross-origin (CROS) iframe , but encountered the same problem on a real device, they use the same set of protocols, what's wrong about it?

@madhusudhanjr
Copy link

madhusudhanjr commented Feb 1, 2017

Does anybody got the solution to this issue?? Please help am completely stuck on iOS Mobile browser.
Unable to play video after switching to iframe. We are using Sauce Labs for testing on Mobile platform.

@ZoharLiran
Copy link

Seeing the same issue. Seem like a pretty common problem. would be happy to pair with someone if there is any direction to a solution.

@midopa
Copy link
Contributor

midopa commented Apr 8, 2017

I had a similar problem and worked around this issue by using a reverse proxy that routed traffic based on request paths.

I also had to get the test site to change the domain it loads the inner iframe content from. This step really depends on the kind of hooks and configuration capabilities your test environment & product have.

I forget the exact details (it was a former job and I have bad memory), but I used Nginx and had a server config that looked something like:

server {
   server_name tests.blahblah.com;
   
   # for inner iframe, as accessed from parent page
   location /inner/iframe/access/path {
      # forward requests to actual url for inner iframe content
      proxy_pass http://dfhkdfsdh.com/content
   }

   # everything else accessed on that parent page
   location / {
      # forward requests to actual url for parent page
      proxy_pass http://asdsfhgjhe.com
   }
}

Then I'd point my tests to go to tests.blahblah.com. Since both the parent and inner iframe are now in the same domain, Safari won't block access due to CORS violations. Then Appium/Webdriver has no trouble switching into that iframe.

Sorry if the details are scant (and likely wrong), my memory is bad, I've left the previous company, and I don't save my work on my personal machines.

@lock
Copy link

lock bot commented Apr 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Apr 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug a problem that needs fixing Mobile Safari related to mobile Safari driver
Projects
None yet
Development

No branches or pull requests