@@ -1763,7 +1763,7 @@ class Playwright extends Helper {
17631763 if ( elements . length === 0 ) {
17641764 throw new ElementNotFound ( locator , 'Element' , 'was not found' )
17651765 }
1766- if ( this . options . strict ) assertOnlyOneElement ( elements , locator )
1766+ if ( this . options . strict ) assertOnlyOneElement ( elements , locator , this )
17671767 return elements [ 0 ]
17681768 }
17691769
@@ -1779,7 +1779,7 @@ class Playwright extends Helper {
17791779 const context = providedContext || ( await this . _getContext ( ) )
17801780 const els = await findCheckable . call ( this , locator , context )
17811781 assertElementExists ( els [ 0 ] , locator , 'Checkbox or radio' )
1782- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
1782+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
17831783 return els [ 0 ]
17841784 }
17851785
@@ -2266,7 +2266,7 @@ class Playwright extends Helper {
22662266 async fillField ( field , value , context = null ) {
22672267 const els = await findFields . call ( this , field , context )
22682268 assertElementExists ( els , field , 'Field' )
2269- if ( this . options . strict ) assertOnlyOneElement ( els , field )
2269+ if ( this . options . strict ) assertOnlyOneElement ( els , field , this )
22702270 const el = els [ 0 ]
22712271
22722272 await el . clear ( )
@@ -2285,7 +2285,7 @@ class Playwright extends Helper {
22852285 async clearField ( locator , context = null ) {
22862286 const els = await findFields . call ( this , locator , context )
22872287 assertElementExists ( els , locator , 'Field to clear' )
2288- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
2288+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
22892289
22902290 const el = els [ 0 ]
22912291
@@ -2302,7 +2302,7 @@ class Playwright extends Helper {
23022302 async appendField ( field , value , context = null ) {
23032303 const els = await findFields . call ( this , field , context )
23042304 assertElementExists ( els , field , 'Field' )
2305- if ( this . options . strict ) assertOnlyOneElement ( els , field )
2305+ if ( this . options . strict ) assertOnlyOneElement ( els , field , this )
23062306 await highlightActiveElement . call ( this , els [ 0 ] )
23072307 await els [ 0 ] . press ( 'End' )
23082308 await els [ 0 ] . type ( value . toString ( ) , { delay : this . options . pressKeyDelay } )
@@ -4300,7 +4300,7 @@ async function findClickable(matcher, locator) {
43004300
43014301 if ( ! matchedLocator . isFuzzy ( ) ) {
43024302 const els = await findElements . call ( this , matcher , matchedLocator )
4303- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
4303+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
43044304 return els
43054305 }
43064306
@@ -4310,7 +4310,7 @@ async function findClickable(matcher, locator) {
43104310 try {
43114311 els = await matcher . getByRole ( 'button' , { name : matchedLocator . value } ) . all ( )
43124312 if ( els . length ) {
4313- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
4313+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
43144314 return els
43154315 }
43164316 } catch ( err ) {
@@ -4320,7 +4320,7 @@ async function findClickable(matcher, locator) {
43204320 try {
43214321 els = await matcher . getByRole ( 'link' , { name : matchedLocator . value } ) . all ( )
43224322 if ( els . length ) {
4323- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
4323+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
43244324 return els
43254325 }
43264326 } catch ( err ) {
@@ -4329,20 +4329,20 @@ async function findClickable(matcher, locator) {
43294329
43304330 els = await findElements . call ( this , matcher , Locator . clickable . narrow ( literal ) )
43314331 if ( els . length ) {
4332- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
4332+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
43334333 return els
43344334 }
43354335
43364336 els = await findElements . call ( this , matcher , Locator . clickable . wide ( literal ) )
43374337 if ( els . length ) {
4338- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
4338+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
43394339 return els
43404340 }
43414341
43424342 try {
43434343 els = await findElements . call ( this , matcher , Locator . clickable . self ( literal ) )
43444344 if ( els . length ) {
4345- if ( this . options . strict ) assertOnlyOneElement ( els , locator )
4345+ if ( this . options . strict ) assertOnlyOneElement ( els , locator , this )
43464346 return els
43474347 }
43484348 } catch ( err ) {
@@ -4619,9 +4619,10 @@ function assertElementExists(res, locator, prefix, suffix) {
46194619 }
46204620}
46214621
4622- function assertOnlyOneElement ( elements , locator ) {
4622+ function assertOnlyOneElement ( elements , locator , helper ) {
46234623 if ( elements . length > 1 ) {
4624- throw new MultipleElementsFound ( locator , elements )
4624+ const webElements = elements . map ( el => new WebElement ( el , helper ) )
4625+ throw new MultipleElementsFound ( locator , webElements )
46254626 }
46264627}
46274628
0 commit comments