@@ -2425,24 +2425,27 @@ class Playwright extends Helper {
24252425 */
24262426 async grabTextFrom ( locator ) {
24272427 const originalLocator = locator
2428- if ( typeof locator === 'object' && ( locator . role || locator . react || locator . vue || locator . pw ) ) {
2429- const els = await this . _locate ( locator )
2428+ const matchedLocator = new Locator ( locator )
2429+
2430+ if ( ! matchedLocator . isFuzzy ( ) ) {
2431+ const els = await this . _locate ( matchedLocator )
24302432 assertElementExists ( els , locator )
24312433 const text = await els [ 0 ] . innerText ( )
24322434 this . debugSection ( 'Text' , text )
24332435 return text
24342436 }
2435- locator = this . _contextLocator ( locator )
2437+
2438+ const contextAwareLocator = this . _contextLocator ( matchedLocator . value )
24362439 let text
24372440 try {
2438- text = await this . page . textContent ( locator )
2441+ text = await this . page . textContent ( contextAwareLocator )
24392442 } catch ( err ) {
24402443 if ( err . message . includes ( 'Timeout' ) || err . message . includes ( 'exceeded' ) ) {
24412444 throw new Error ( `Element ${ new Locator ( originalLocator ) . toString ( ) } was not found by text|CSS|XPath` )
24422445 }
24432446 throw err
24442447 }
2445- assertElementExists ( text , locator )
2448+ assertElementExists ( text , contextAwareLocator )
24462449 this . debugSection ( 'Text' , text )
24472450 return text
24482451 }
@@ -3865,26 +3868,22 @@ async function proceedClick(locator, context = null, options = {}) {
38653868}
38663869
38673870async function findClickable ( matcher , locator ) {
3868- if ( locator . react ) return findReact ( matcher , locator )
3869- if ( locator . vue ) return findVue ( matcher , locator )
3870- if ( locator . pw ) return findByPlaywrightLocator . call ( this , matcher , locator )
3871- if ( locator . role ) return findByRole ( matcher , locator )
3871+ const matchedLocator = new Locator ( locator )
38723872
3873- locator = new Locator ( locator )
3874- if ( ! locator . isFuzzy ( ) ) return findElements . call ( this , matcher , locator )
3873+ if ( ! matchedLocator . isFuzzy ( ) ) return findElements . call ( this , matcher , matchedLocator )
38753874
38763875 let els
3877- const literal = xpathLocator . literal ( locator . value )
3876+ const literal = xpathLocator . literal ( matchedLocator . value )
38783877
38793878 try {
3880- els = await matcher . getByRole ( 'button' , { name : locator . value } ) . all ( )
3879+ els = await matcher . getByRole ( 'button' , { name : matchedLocator . value } ) . all ( )
38813880 if ( els . length ) return els
38823881 } catch ( err ) {
38833882 // getByRole not supported or failed
38843883 }
38853884
38863885 try {
3887- els = await matcher . getByRole ( 'link' , { name : locator . value } ) . all ( )
3886+ els = await matcher . getByRole ( 'link' , { name : matchedLocator . value } ) . all ( )
38883887 if ( els . length ) return els
38893888 } catch ( err ) {
38903889 // getByRole not supported or failed
@@ -3903,7 +3902,7 @@ async function findClickable(matcher, locator) {
39033902 // Do nothing
39043903 }
39053904
3906- return findElements . call ( this , matcher , locator . value ) // by css or xpath
3905+ return findElements . call ( this , matcher , matchedLocator . value ) // by css or xpath
39073906}
39083907
39093908async function proceedSee ( assertType , text , context , strict = false ) {
@@ -3942,16 +3941,12 @@ async function findCheckable(locator, context) {
39423941 contextEl = contextEl [ 0 ]
39433942 }
39443943
3945- if ( typeof locator === 'object' && ( locator . role || locator . react || locator . vue || locator . pw ) ) {
3946- return findElements . call ( this , contextEl , locator )
3947- }
3948-
39493944 const matchedLocator = new Locator ( locator )
39503945 if ( ! matchedLocator . isFuzzy ( ) ) {
3951- return findElements . call ( this , contextEl , matchedLocator . simplify ( ) )
3946+ return findElements . call ( this , contextEl , matchedLocator )
39523947 }
39533948
3954- const literal = xpathLocator . literal ( locator )
3949+ const literal = xpathLocator . literal ( matchedLocator . value )
39553950 let els = await findElements . call ( this , contextEl , Locator . checkable . byText ( literal ) )
39563951 if ( els . length ) {
39573952 return els
@@ -3960,7 +3955,7 @@ async function findCheckable(locator, context) {
39603955 if ( els . length ) {
39613956 return els
39623957 }
3963- return findElements . call ( this , contextEl , locator )
3958+ return findElements . call ( this , contextEl , matchedLocator . value )
39643959}
39653960
39663961async function proceedIsChecked ( assertType , option ) {
@@ -3972,9 +3967,6 @@ async function proceedIsChecked(assertType, option) {
39723967}
39733968
39743969async function findFields ( locator ) {
3975- if ( typeof locator === 'object' && ( locator . role || locator . react || locator . vue || locator . pw ) ) {
3976- return this . _locate ( locator )
3977- }
39783970 const matchedLocator = new Locator ( locator )
39793971 if ( ! matchedLocator . isFuzzy ( ) ) {
39803972 return this . _locate ( matchedLocator )
0 commit comments