Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何正确评估从Behat到Selenium的javascript代码?_Javascript_Php_Selenium_Behat_Mink - Fatal编程技术网

如何正确评估从Behat到Selenium的javascript代码?

如何正确评估从Behat到Selenium的javascript代码?,javascript,php,selenium,behat,mink,Javascript,Php,Selenium,Behat,Mink,我有以下基于自定义步骤定义的代码: $js = <<<JS function checkVisibility( elm, evalType ) { evalType = evalType || "visible"; var vpH = jQuery(window).height(), // Viewport Height st = jQuery(window).scrollTop(), // Scrol

我有以下基于自定义步骤定义的代码:

    $js = <<<JS

    function checkVisibility( elm, evalType ) {
        evalType = evalType || "visible";

        var vpH = jQuery(window).height(), // Viewport Height
            st = jQuery(window).scrollTop(), // Scroll Top
            y = jQuery(elm).offset().top,
            elementHeight = jQuery(elm).height();

        if (evalType === "visible") return ((y < (vpH + st)) && (y > (st - elementHeight)));
        if (evalType === "above") return ((y < (vpH + st)));
    }  

    var el = document.querySelector("$locator");
    return checkVisibility(el, "visible");
JS;


    $result = $this->getSession()->evaluateScript($js);

我有一个类似于贝娄的东西可以工作:

    $js = <<<JS

    (function myFunction() {
      //function content
    })()
JS;

当您将return true设置为myFunction时,您在PHP中也会得到true?是的,我在PHP中也会得到true。我使用的是页面对象,我有$this->getDriver->evaluateScriptreturn$函数;在页面对象中。所以我的环境有问题。在我的例子中,$result总是空的:/n您使用phantomjs作为浏览器吗?不,我使用的是chrome。为什么不使用isVisible方法呢?你有没有试过,但不起作用?
    $js = <<<JS

    (function myFunction() {
      //function content
    })()
JS;
$result = $this->getSession()->evaluateScript("return $js");