使用ID切换带有Codeception的IFrame [英] Switch IFrame with Codeception using ID

查看:101
本文介绍了使用ID切换带有Codeception的IFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ID切换到具有Codeception的IFrame?实际上,我可以使用IFrame的名称,但不能使用ID-> Codeception SwitchToIFrame



IFrame示例:

 < iframe id = iframeToolbar src = link frameborder = 0 style = position:固定;左侧:0px;顶部:0px; z-index:998;宽度:940px; scrolling = no width = 100px height = 100%>< / iframe> 

代码接收示例:

 <?php 
#切换到iframe
$ I-> switchToIFrame( another_frame);
#切换到父页面
$ I-> switchToIFrame();

是否可能是Codeception<-> Facebook Webdriver连接问题?



编辑:我重新安装了Codeception,然后按照快速步骤指南进行操作。结果-问题仍然存在:Codeception和Facebook Webdriver不想一起工作。 我的密码识别码



accept.suite.yml:

  actor:AcceptanceTester 
模块:
已启用:
- \帮助程序\接受
-WebDriver:
网址:https://xxxxxxxxxxxxxx.com
浏览器:chrome
window_size:最大化
clear_cookies:true

codeception.yml:

 路径:
测试:测试
输出:tests / _output
数据:tests / _data
支持:tests / _support
envs:tests / _envs
actor_suffix:测试程序
扩展名:
启用:
-Codeception\Extension\RunFailed
设置:
颜色:真




  • 操作系统:Windows 10

  • PHP:7.1.7

  • PHPUnit:6.4.4

  • 硒服务器:3.8.1

  • 代码接收:2.3.7

  • Chrome:63.0.3239.108


解决方案

我遇到了这个问题,测试了一个带有Google reCaptcha的页面... reCaptcha本身iframe,并且由于该iframe是由第三方代码生成的,因此我们无法控制其name属性(至少是在其首次生成时)。



我最终得到了什么做的是运行一个JavaScript代码段,该代码段可以根据其他内容找到iframe,然后为其指定ID,以便Codeception Webdriver可以切换到该代码段:

 公共函数_clickOnCaptcha(AcceptanceTester $ I)
{
//为Recaptcha iframe命名,以便代码接收Web驱动程序可以切换到它
$ recaptcha_frame_name ='recaptcha-frame' ;
$ I-> executeJS( $('。g-recaptcha iframe')。attr('name','$ recaptcha_frame_name'));;
$ I-> switchToIFrame($ recaptcha_frame_name);
$ I->参见(不是机器人);
$ I-> seeElement(’。rc-anchor’);
$ I-> click([[id] =>‘recaptcha-anchor’]);
$ I-> switchToIFrame(); //切换回主窗口
}

我确实可以控制包含的元素,因此在这种情况下,它包含在类 g-recaptcha 的元素中...因此,我们使用jquery在该元素内找到iframe: $ ('.g-recaptcha iframe'),然后为其指定名称属性: .attr('name','$ recaptcha_frame_name')



然后,我们可以使用Codeception切换到它并单击验证码复选框:

$ I->。 switchToIFrame($ recaptcha_frame_name);
$ I-> click([[id] =>‘recaptcha-anchor’]);



然后,完成后,切换回主框架,以便我们提交表单:

$ I-> switchToIFrame(); //切换回主窗口



NB,我正在使用reCaptcha测试键(如此处指定)测试环境,因此它永远不会真正要求解决验证码。



https://developers.google.com/recaptcha/docs/faq


具有以下内容测试密钥,您将永远不会获得任何验证码,并且所有验证请求都将通过。 -vFI1TnRWxMZNFuojJ4WifJWe
reCAPTCHA小部件将显示警告消息,声称它仅用于测试目的。请不要将这些密钥用于您的生产流量。




How can I switch to an IFrame with Codeception using ID? Actually I can use the name of the IFrame but not the ID -> Codeception SwitchToIFrame

IFrame Example:

<iframe id="iframeToolbar" src="link" frameborder="0" style="position: fixed; left: 0px; top: 0px; z-index: 998; width: 940px;" scrolling="no" width="100px" height="100%"></iframe>

Codeception Example:

<?php
# switch to iframe
$I->switchToIFrame("another_frame");
# switch to parent page
$I->switchToIFrame();

Is it maybe a Codeception <-> Facebook Webdriver Connection Problem?

EDIT: I reinstalled Codeception, followed the Quick Step Guide. Result - the Problem is still the same: Codeception and the Facebook Webdriver doesn't want to work together. My Codeception Code

acceptance.suite.yml:

actor: AcceptanceTester
modules:
  enabled:
    - \Helper\Acceptance
    - WebDriver:
            url: https://xxxxxxxxxxxxxx.com
            browser: chrome
            window_size: maximize
            clear_cookies: true

codeception.yml:

paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
    - Codeception\Extension\RunFailed
settings:
colors: true

  • OS: Windows 10
  • PHP: 7.1.7
  • PHPUnit: 6.4.4
  • Selenium Server: 3.8.1
  • Codeception: 2.3.7
  • Chrome: 63.0.3239.108

解决方案

I had this issue, testing a page with a Google reCaptcha in it ... the reCaptcha is in its own iframe, and since that iframe is generated by 3rd-party code, we have no control over its name attribute (at least when it's first generated).

What I ended up doing was running a javascript snippet which can find the iframe based on other things, and then giving it an id, so that Codeception Webdriver could switch to it:

    public function _clickOnCaptcha(AcceptanceTester $I)
{
    // give the recaptcha iframe a name so codeception webdriver can switch to it
    $recaptcha_frame_name = 'recaptcha-frame';
    $I->executeJS("$('.g-recaptcha iframe').attr('name', '$recaptcha_frame_name')");
    $I->switchToIFrame($recaptcha_frame_name);
    $I->see('not a robot');
    $I->seeElement('.rc-anchor');
    $I->click(['id' => 'recaptcha-anchor']);
    $I->switchToIFrame(); // switch back to main window
}

I did have control over the containing elements, so in this case, it's contained within an element with class g-recaptcha ... so we use jquery to find the iframe inside that element: $('.g-recaptcha iframe'), and then give it a name attribute: .attr('name', '$recaptcha_frame_name').

Then we can use Codeception to switch to it and click the captcha checkbox: $I->switchToIFrame($recaptcha_frame_name); $I->click(['id' => 'recaptcha-anchor']);

Then, when we're done, switch back out to the main frame so we can submit our form: $I->switchToIFrame(); // switch back to main window

NB, I'm using the reCaptcha test keys, as specified here, in the testing environment so that it will never actually ask to solve a captcha.

https://developers.google.com/recaptcha/docs/faq

With the following test keys, you will always get No CAPTCHA and all verification requests will pass.

Site key: 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI Secret key: 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe The reCAPTCHA widget will show a warning message to claim that it's only for testing purposes. Please do not use these keys for your production traffic.

这篇关于使用ID切换带有Codeception的IFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆