我在網頁上的按鈕:查找與類使用貂一個div和貝哈特
<div class="button wide green attached connectyourself" >Conect</div>
我希望在這個div恩推,所以我創建了Methode:
/**
* @When I open the connection popup
*/
public function iOpenTheConnectionPopup()
{
$page = $this->getSession()->getPage();
$findName = $page->find("css", '.connectyourself');
if (!$findName) {
throw new Exception('connectyourself' . " could not be found");
} else {
$findName->click();
}
}
每當我得到異常'connectyourself could not be found'。 你能幫我嗎?
你的檢查,如果發現該元素是不正確的,'find'返回一個對象或空,因此你應該使用'=== null',而不是'!$ findName'也檢查你的選擇退貨單元素,最後也許你需要一些等待,在這裏檢查https://stackoverflow.com/questions/42911114/fatal-error-call-to-a-member-function-press-on-a-non-object/42925010 – lauda
as @lauda提到,請檢查你的陳述,並且在搜索之前考慮等待元素。最後,您可能會將您的CSS選擇器精煉爲div.connectyourself –