如何正确评估从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");