@@ -1780,7 +1780,7 @@ export function tests() {
17801780 await I . seeElement ( { role : 'checkbox' } )
17811781
17821782 // Test count of elements with same role
1783- await I . seeNumberOfVisibleElements ( { role : 'button' } , 3 )
1783+ await I . seeNumberOfVisibleElements ( { role : 'button' } , 4 )
17841784 await I . seeNumberOfVisibleElements ( { role : 'combobox' } , 4 )
17851785 await I . seeNumberOfVisibleElements ( { role : 'checkbox' } , 2 )
17861786 } )
@@ -1789,7 +1789,8 @@ export function tests() {
17891789 await I . amOnPage ( '/form/role_elements' )
17901790
17911791 // Test role with text (exact match)
1792- await I . seeElement ( { role : 'button' , text : 'Submit Form' } )
1792+ await I . seeElement ( { role : 'button' , text : 'Submit' } )
1793+ await I . seeElement ( { role : 'button' , text : 'Dont Submit' } )
17931794 await I . seeElement ( { role : 'button' , text : 'Cancel' } )
17941795 await I . seeElement ( { role : 'button' , text : 'Reset' } )
17951796
@@ -1823,7 +1824,7 @@ export function tests() {
18231824 await I . seeInField ( { role : 'textbox' , text : 'Enter your message' } , 'This is a test message' )
18241825
18251826 // Click button by role and text
1826- await I . click ( { role : 'button' , text : 'Submit Form ' } )
1827+ await I . click ( { role : 'button' , text : 'Submit' } )
18271828 await I . see ( 'Form Submitted!' )
18281829 await I . see ( 'Form data submitted' )
18291830 } )
@@ -1853,14 +1854,14 @@ export function tests() {
18531854
18541855 // Test grabbing multiple elements
18551856 const buttons = await I . grabWebElements ( { role : 'button' } )
1856- assert . equal ( buttons . length , 3 )
1857+ assert . equal ( buttons . length , 4 )
18571858
18581859 const comboboxes = await I . grabWebElements ( { role : 'combobox' } )
18591860 assert . equal ( comboboxes . length , 4 )
18601861
18611862 // Test grabbing specific element
18621863 if ( ! isHelper ( 'WebDriver' ) ) {
1863- const submitButton = await I . grabWebElement ( { role : 'button' , text : 'Submit Form ' } )
1864+ const submitButton = await I . grabWebElement ( { role : 'button' , text : 'Submit' } )
18641865 assert . ok ( submitButton )
18651866 }
18661867
@@ -1887,7 +1888,7 @@ export function tests() {
18871888 await I . seeInField ( { role : 'combobox' , text : 'Title' } , 'Software Engineer' )
18881889
18891890 // Submit and verify data is processed correctly
1890- await I . click ( { role : 'button' , text : 'Submit Form ' } )
1891+ await I . click ( { role : 'button' , text : 'Submit' } )
18911892 await I . see ( 'Form Submitted!' )
18921893 await I . see ( 'John Doe' )
18931894 await I . see ( 'Technology' )
@@ -1902,7 +1903,7 @@ export function tests() {
19021903 await I . click ( 'Reset' )
19031904 await I . dontSeeInField ( 'Title' , 'Test' )
19041905
1905- await I . click ( 'Submit Form ' )
1906+ await I . click ( 'Submit' )
19061907 await I . see ( 'Form Submitted!' )
19071908 } )
19081909
@@ -1912,7 +1913,7 @@ export function tests() {
19121913 await I . fillField ( 'Title' , 'Test Title' )
19131914 await I . fillField ( 'Name' , 'John Doe' )
19141915
1915- await I . click ( 'Submit Form ' )
1916+ await I . click ( 'Submit' )
19161917 await I . see ( 'Form Submitted!' )
19171918 await I . see ( 'Test Title' )
19181919 await I . see ( 'John Doe' )
@@ -1964,11 +1965,43 @@ export function tests() {
19641965 await I . checkOption ( 'Subscribe to newsletter' )
19651966 }
19661967
1967- await I . click ( 'Submit Form ' )
1968+ await I . click ( 'Submit' )
19681969 await I . see ( 'Form Submitted!' )
19691970 await I . see ( 'Product Manager' )
19701971 await I . see ( 'Bob Johnson' )
19711972 await I . see ( 'Product' )
19721973 } )
1974+
1975+ it ( 'should click the correct button when multiple buttons have similar text' , async ( ) => {
1976+ await I . amOnPage ( '/form/role_elements' )
1977+
1978+ // Fill form with test data
1979+ await I . fillField ( 'Title' , 'Test Data' )
1980+ await I . fillField ( 'Name' , 'Test User' )
1981+
1982+ // Click 'Submit' button - should NOT click 'Dont Submit'
1983+ await I . click ( 'Submit' )
1984+
1985+ // Verify form was submitted (meaning the correct 'Submit' button was clicked)
1986+ await I . see ( 'Form Submitted!' )
1987+ await I . see ( 'Test Data' )
1988+ await I . see ( 'Test User' )
1989+
1990+ // Reset and test again to be sure
1991+ await I . click ( 'Reset' )
1992+ await I . dontSee ( 'Form Submitted!' )
1993+
1994+ // Fill form again
1995+ await I . fillField ( 'Title' , 'Another Test' )
1996+ await I . fillField ( 'Name' , 'Another User' )
1997+
1998+ // Click 'Submit' button again
1999+ await I . click ( 'Submit' )
2000+
2001+ // Verify form was submitted again
2002+ await I . see ( 'Form Submitted!' )
2003+ await I . see ( 'Another Test' )
2004+ await I . see ( 'Another User' )
2005+ } )
19732006 } )
19742007}
0 commit comments