Reputation: 1307
I am trying to find an element which is within iframe. So i try to switch to iframe.
The iframe in html:
<iframe id="id_of_iframe" data-app-id="com.s-h.ph.pr" class="external-app ng-scope ng-isolate-scope" ng-if="!vm.appDisabled" ng-attr-sandbox="{{vm.iframeConfig.sandbox ? vm.iframeConfig.sandbox : ''}}" tp-onload="vm.sendCurrentRouteToIFrame()" style="border: none; border-width: 0; height: 100%; width: 100%; display: block;" sandbox="allow-forms allow-popups allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation allow-modals"></iframe>
code used:
browser.switchTo().frame('id_of_iframe');
I get the following error:
Failed: no such frame
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c58
10906a),platform=Windows NT 6.1.7601 SP1 x86_64)
Stack:
NoSuchFrameError: no such frame
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c58
10906a),platform=Windows NT 6.1.7601 SP1 x86_64)
at WebDriverError (C:\Users\z002ex9t\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\selenium-webdriver\lib\error.js:27:5)
at NoSuchFrameError (C:\Users\z002ex9t\AppData\Roaming\npm\node_modules\
protractor\node_modules\selenium-webdriver\lib\error.js:180:5)
at Object.checkLegacyResponse (C:\Users\z002ex9t\AppData\Roaming\npm\nod
e_modules\protractor\node_modules\selenium-webdriver\lib\error.js:505:15)
at parseHttpResponse (C:\Users\z002ex9t\AppData\Roaming\npm\node_modules
\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\Users\z002ex9t\AppData\Roaming\npm\node_modu
les\protractor\node_modules\selenium-webdriver\lib\http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:109:7)
I am using the following versions : "protractor": "5.1.2", "jasmine": "2.8.0" webdriver-manager 12.0.6
Any idea how to solve this issue?
Thanks in advance.
Upvotes: 0
Views: 757
Reputation: 4832
WebDriver's driver.switchTo().frame()
method takes one of the three possible arguments:
Example:
Consider below iframes are available in your DOM.
Iframe1:
<iframe name="iframe1" id="iframe_1" class="iframe_1">
</iframe>
Iframe2:
<iframe name="iframe2" id="iframe_2" class="iframe_2">
</iframe>
Iframe3:
<iframe name="iframe3" id="iframe_3" class="iframe_3">
</iframe>
Using Index:
browser.switchTo().frame(0)
- This will switch to iframe1
browser.switchTo().frame(1)
- This will switch to iframe2
browser.switchTo().frame(2)
- This will switch to iframe3
Name or ID:
browser.switchTo().frame("iframe1")
or browser.switchTo().frame("iframe_1")
- This will switch to iframe1
browser.switchTo().frame("iframe2")
or browser.switchTo().frame("iframe_2")
- This will switch to iframe2
browser.switchTo().frame("iframe3")
or browser.switchTo().frame("iframe_3")
- This will switch to iframe3
WebElement
browser.switchTo().frame(element(by.tagName("iframe")).getWebElement())
or browser.switchTo().frame(element(by.css(".iframe_1")).getWebElement())
- This will switch to iframe1
browser.switchTo().frame(element(by.css(".iframe_2")).getWebElement())
or browser.switchTo().frame(element(by.xpath(".//iframe[@id='iframe_2']")).getWebElement())
- This will switch to iframe2
Upvotes: 1
Reputation: 370
Can you please try with passing index by giving
browser.switchTo().frame("index of the frame");
This is the most simple one and may be we can figure out whether it was an issue with id or something else. Because the id you have given is straight forward and I don't see a reason why it should fail
Upvotes: 1
Reputation: 4739
If there is a frame use xpath
//iframe[@data-app-id='com.s-h.ph.pr']
But still I suggest you first have to used id
Upvotes: 0