2017-06-29 80 views
-2

我在網頁上的按鈕:查找與類使用貂一個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'。 你能幫我嗎?

+1

你的檢查,如果發現該元素是不正確的,'find'返回一個對象或空,因此你應該使用'=== null',而不是'!$ findName'也檢查你的選擇退貨單元素,最後也許你需要一些等待,在這裏檢查https://stackoverflow.com/questions/42911114/fatal-error-call-to-a-member-function-press-on-a-non-object/42925010 – lauda

+0

as @lauda提到,請檢查你的陳述,並且在搜索之前考慮等待元素。最後,您可能會將您的CSS選擇器精煉爲div.connectyourself –

回答

0

我認爲這個CSS不是唯一的。可能會有更多元素與類名稱包含「connectyourself」。你應該嘗試通過給予全班級nam來找到它。

$findName = $page->find("css", '.button.wide.green.attached.connectyourself'); 
+0

我收到錯誤:'element not visible' – user7424312

+0

@ user7424312,您是否嘗試過至少在Google上搜索相同的錯誤。在粘貼評論之前。 – NarendraR