@@ -58,14 +58,8 @@ public function iAmOnUrlComposedBy(TableNode $tableNode)
58
58
*/
59
59
public function iClickOnTheNthElement ($ index , $ element )
60
60
{
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 ();
69
63
}
70
64
71
65
/**
@@ -75,17 +69,21 @@ public function iClickOnTheNthElement($index, $element)
75
69
*/
76
70
public function iFollowTheNthLink ($ index , $ link )
77
71
{
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
+ }
87
76
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 ();
89
87
}
90
88
91
89
/**
0 commit comments