@@ -58,14 +58,8 @@ public function iAmOnUrlComposedBy(TableNode $tableNode)
5858 */
5959 public function iClickOnTheNthElement ($ index , $ element )
6060 {
61- $ nodes = $ this ->getSession ()->getPage ()->findAll ('css ' , $ element );
62-
63- if (isset ($ nodes [$ index - 1 ])) {
64- $ nodes [$ index - 1 ]->click ();
65- }
66- else {
67- throw new \Exception ("The element ' $ element' number $ index was not found anywhere in the page " );
68- }
61+ $ node = $ this ->findElement ('css ' , $ element , $ index );
62+ $ node ->click ();
6963 }
7064
7165 /**
@@ -75,17 +69,21 @@ public function iClickOnTheNthElement($index, $element)
7569 */
7670 public function iFollowTheNthLink ($ index , $ link )
7771 {
78- $ page = $ this ->getSession ()->getPage ();
79-
80- $ links = $ page ->findAll ('named ' , [
81- 'link ' , $ this ->getSession ()->getSelectorsHandler ()->xpathLiteral ($ link )
82- ]);
83-
84- if (!isset ($ links [$ index - 1 ])) {
85- throw new \Exception ("The $ index element ' $ link' was not found anywhere in the page " );
86- }
72+ $ element = ['link ' , $ this ->getSession ()->getSelectorsHandler ()->xpathLiteral ($ link )];
73+ $ node = $ this ->findElement ('named ' , $ element , $ index );
74+ $ node ->click ();
75+ }
8776
88- $ links [$ index - 1 ]->click ();
77+ /**
78+ * Presses the nth specified button
79+ *
80+ * @When (I )press the :index :button button
81+ */
82+ public function pressTheNthButton ($ index , $ button )
83+ {
84+ $ element = ['button ' , $ this ->getSession ()->getSelectorsHandler ()->xpathLiteral ($ button )];
85+ $ node = $ this ->findElement ('named ' , $ element , $ index );
86+ $ node ->click ();
8987 }
9088
9189 /**
0 commit comments