mirror of
https://github.com/appium/appium.git
synced 2026-05-24 21:08:51 -05:00
Merge pull request #6566 from scottdixon/iframe
README: cross-domain iframes
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
## Cross-domain iFrame Automation
|
||||
|
||||
[Same-origin policy](https://en.wikipedia.org/wiki/Same-origin_policy) prevents Appium from automating iFrames that have a different domain to the parent.
|
||||
|
||||
### Subdomain workaround
|
||||
If the parent and the iFrame share the same domain (e.g. `site.com` and `shop.site.com`), you can
|
||||
set `document.domain` on both the parent and each iFrame to a common domain. This solves the same-origin policy issue and allows automation. For example:
|
||||
|
||||
Parent:
|
||||
```
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
document.domain = 'site.com';
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="http://shop.site.com" width="200" height="200"></iframe>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
Child iFrame:
|
||||
```
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
document.domain = 'site.com';
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>This is an iFrame!</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Reference in New Issue
Block a user