【问题标题】:How to execute Javascript with Codeception and get the returned values如何使用 Codeception 执行 Javascript 并获取返回值
【发布时间】:2019-11-20 10:15:59
【问题描述】:

有什么办法可以使这项工作?

    $I->amOnPage('/');

    $I->wait(2);

    $I->executeJS('
        var theCookies = document.cookie.split(\';\');
        var aString = \'\';
        for (var i = 1 ; i <= theCookies.length; i++) {
            aString += i + \' \' + theCookies[i-1] + "\n";
        }
        return aString;
    ');

除了我得到一个错误之外,这样的事情可能吗?

【问题讨论】:

  • 试试 $I->executeJS('return document.cookie.split(\';\')')
  • @Murthi 嘿,这确实有效,但它没有显示任何 3rd 方 cookie,至少不是我在浏览器中可以看到的所有内容

标签: selenium codeception


【解决方案1】:

记录在这里:https://codeception.com/docs/modules/WebDriver

执行JS

执行自定义 JavaScript。

本示例使用 jQuery 获取值并将该值分配给 PHP 变量:

$myVar = $I->executeJS('return $("#myField").val()');

// additional arguments can be passed as array
// Example shows `Hello World` alert:
$I->executeJS("window.alert(arguments[0])", ['Hello world']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 2015-05-26
    • 2013-08-01
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多