2017-09-28 44 views
0

我试图找到iframe内的元素。所以我尝试切换到iframe。无法在量角器测试中找到iframe

在HTML中的iframe:使用

<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> 

代码:

browser.switchTo().frame('id_of_iframe'); 

我收到以下错误:

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) 

我使用以下版本: “量角器” :“5.1.2”, “茉莉花”:“2.8.0” webdriver-manager 12.0.6

任何想法如何解决这个问题?

在此先感谢。

+0

我不明白你为什么要提供它仅含有该行代码段,这应该是是可测试? – user10089632

+0

请分享HTML和网址 – iamsankalp89

+0

失败:没有这样的框架问题说这是真的有框架 – iamsankalp89

回答

1

能否请您给予

browser.switchTo().frame("index of the frame"); 

这是通过指数尝试最简单的一个,也许我们可以弄清楚它是否是id或其他问题。因为你给的ID是直线前进,我没有看到一个原因,它应该会失败

+0

它没有必要它有只有一帧 – iamsankalp89

+0

是的,你是对的。我相应地编辑了我的答案 –

+0

@aayya他尝试了相同的解决方案。奇怪,为什么它nt工作 – iamsankalp89

0

如果有一个框架使用xpath

//iframe[@data-app-id='com.s-h.ph.pr'] 

但我仍建议你首先要使用id

1

的webdriver的driver.switchTo().frame()方法采用的三种可能的参数之一:

  1. 号码(iframe的指数)
  2. 名称或ID(如果IFRAME具有ID或名称属性)
  3. WebElement(如果iframe中需要由任何定制逻辑来识别)

示例:

请考虑以下iframe在您的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> 

使用索引:

  • browser.switchTo().frame(0) - 这将切换到iframe1
  • browser.switchTo().frame(1) - 这将切换到iframe2
  • browser.switchTo().frame(2) - 这将切换到iframe3

名称或ID:

  • browser.switchTo().frame("iframe1")browser.switchTo().frame("iframe_1") - 这将切换到iframe1
  • browser.switchTo().frame("iframe2")browser.switchTo().frame("iframe_2") - 这将切换到iframe2
  • browser.switchTo().frame("iframe3")browser.switchTo().frame("iframe_3") - 这将切换到iframe3

WebElement

  • browser.switchTo().frame(element(by.tagName("iframe")).getWebElement())browser.switchTo().frame(element(by.css(".iframe_1")).getWebElement()) - 这将切换到iframe1
  • browser.switchTo().frame(element(by.css(".iframe_2")).getWebElement())browser.switchTo().frame(element(by.xpath(".//iframe[@id='iframe_2']")).getWebElement()) - 这将切换到iframe2
相关问题