2013-08-08 11 views
5

używam następującą funkcję:Nie można oceniać XPath (Behat/Mink)

/** 
    * Click on the element with the provided xpath query 
    * 
    * @When /^I click on the element with xpath "([^"]*)"$/ 
    */ 
    public function iClickOnTheElementWithXPath($xpath) 
    { 
     $session = $this->getSession(); // get the mink session 
     $element = $session->getPage()->find('xpath',$session->getSelectorsHandler()->selectorToXpath('xpath', $xpath)); // runs the actual query and returns the element 

     // errors must not pass silently 
     if (null === $element) { 
      throw new \InvalidArgumentException(sprintf('Could not evaluate XPath: "%s"', $xpath)); 
     } 

     // ok, let's click on it 
     $element->click(); 

    } 

w moim FeatureContext.php próbuje kliknij na przycisku z następującym XPath (The Behat Krok jest): Kiedy klikam na elemencie z XPath

//html/body/div[4]/div/div/div/div[2]/div[2]/div[4]/div/div/div/div[2]/ol/li/span[4]/a[1] 

Firebug jest zadowolony z tego XPath, ale behat daje mi błąd:

Could not evaluate XPath: "//html/body/div[4]/div/div/div/div[2]/div[2]/div[4]/div/div/div/div[2]/ol/li/span[4]/a[1]"

Co robię źle?

tutaj jest przykładem Behat na w3schools, próbując kliknąć na przycisk "Spróbuj to sam" przycisk ":

   Feature: xpath try on w3schools.com/tags/att_input_src.asp 
      Scenario: click button on xpath 
       @javascript 
      When I go to "/tags/att_input_src.asp" 
       And I click on the element with xpath "/html/body/div/div[3]/div[6]/div/a[1]" 
       And I wait 5 seconds 
      Then I should be on "tags/tryit.asp?filename=tryhtml_input_src" 

daje ten sam błąd, nie mógł ocenić XPath The XPath na Firebug pokazuje poprawne przycisk ...

+0

Twoje wyrażenie XPath prawdopodobnie po prostu nie zwraca niczego. Czy możesz podać nam próbki danych do pracy? –

+0

ten sam xpath zwrócił prawidłową lokalizację, gdy jest zaznaczony na firebugu –

Odpowiedz

6

miałem ten sam problem. wydaje się, że musisz pominąć /html/body. dla mnie

//div[2]/div/div[2]/div/table/tbody/tr/td[3] 

działa dobrze.

+0

niesamowitym! To działa! Jesteś gwiazdą! –

Powiązane problemy