Selenium webdriver PHPUnit和Webdriver(Selenium2)-无法将字符串参数传递给waitUntil()方法

Selenium webdriver PHPUnit和Webdriver(Selenium2)-无法将字符串参数传递给waitUntil()方法,selenium-webdriver,phpunit,Selenium Webdriver,Phpunit,环境: -Selenium 2.39独立服务器 -PHP 5.4.11 -PHPUnit 3.7.28 -Chrome V31和ChromeDriver v2.7 在阅读示例之后,我想用waitill()方法封装一个查找元素的方法。我试了几次,如下所示: 代码1: public function findElement($elementCssPath){ $this->waitUntil(function($testCase) { try { $testCase->byCssSel

环境:
-Selenium 2.39独立服务器
-PHP 5.4.11
-PHPUnit 3.7.28
-Chrome V31和ChromeDriver v2.7
在阅读示例之后,我想用
waitill()
方法封装一个查找元素的方法。我试了几次,如下所示:

代码1:

public function findElement($elementCssPath){
$this->waitUntil(function($testCase) {
try {
$testCase->byCssSelector($elementCssPath);
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
return TRUE;
}
}, 8000);
}
public function findElement($elementCssPath){
$this->waitUntil(function () {
if ($this->byCssSelector($elementCssPath)) {
return true;
}
return null;
}, 20000);
}
public function findElement($elementCssPath){
$this->waitUntil(function($elementCssPath) {
try {
$this->byCssSelector($elementCssPath);
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
return TRUE;
}
}, 8000);
}
代码2:

public function findElement($elementCssPath){
$this->waitUntil(function($testCase) {
try {
$testCase->byCssSelector($elementCssPath);
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
return TRUE;
}
}, 8000);
}
public function findElement($elementCssPath){
$this->waitUntil(function () {
if ($this->byCssSelector($elementCssPath)) {
return true;
}
return null;
}, 20000);
}
public function findElement($elementCssPath){
$this->waitUntil(function($elementCssPath) {
try {
$this->byCssSelector($elementCssPath);
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
return TRUE;
}
}, 8000);
}
代码3:

public function findElement($elementCssPath){
$this->waitUntil(function($testCase) {
try {
$testCase->byCssSelector($elementCssPath);
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
return TRUE;
}
}, 8000);
}
public function findElement($elementCssPath){
$this->waitUntil(function () {
if ($this->byCssSelector($elementCssPath)) {
return true;
}
return null;
}, 20000);
}
public function findElement($elementCssPath){
$this->waitUntil(function($elementCssPath) {
try {
$this->byCssSelector($elementCssPath);
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
return TRUE;
}
}, 8000);
}
但他们都报告了一个错误:

Undefined variable: elementCssPath 
我在网上搜索了很多,但没有进一步的信息。

请帮忙,谢谢

这段代码终于适合我了

public function findElementWaitUntil($elementCssPath){
    $this->waitUntil(function() use($elementCssPath){
        if ($this->byCssSelector($elementCssPath)) {
                return true;
            }
                return null;
            }, 10000);
    try{
        $object=$this->byCssSelector($elementCssPath);
        return $object;
    }
    catch(Exception $e){
        throw $e;
    }   
}

如果元素在超时之前未显示,则会发生内存泄漏。