@@ -299,6 +299,49 @@ class Locator {
299299    return  new  Locator ( {  xpath } ) ; 
300300  } 
301301
302+   /** 
303+      * Adds condition: attribute value starts with text 
304+      * (analog of XPATH: [starts-with(@attr,'startValue')] or CSS [attr^='startValue'] 
305+      * Example: I.click(locate('a').withAttrStartsWith('href', 'https://'))); 
306+      * Works with any attribute: class, href etc. 
307+      * @param  {string } attrName 
308+      * @param  {string } startsWith 
309+      * @returns  {Locator } 
310+     */ 
311+   withAttrStartsWith ( attrName ,  startsWith )  { 
312+     const  xpath  =  sprintf ( '%s[%s]' ,  this . toXPath ( ) ,  `starts-with(@${ attrName } ${ startsWith }  ) ; 
313+     return  new  Locator ( {  xpath } ) ; 
314+   } 
315+ 
316+   /** 
317+     * Adds condition: attribute value ends with text 
318+     * (analog of XPATH: [ends-with(@attr,'endValue')] or CSS [attr$='endValue'] 
319+     * Example: I.click(locate('a').withAttrEndsWith('href', '.com'))); 
320+     * Works with any attribute: class, href etc. 
321+     * @param  {string } attrName 
322+     * @param  {string } endsWith 
323+     * @returns  {Locator } 
324+   */ 
325+   withAttrEndsWith ( attrName ,  endsWith )  { 
326+     const  xpath  =  sprintf ( '%s[%s]' ,  this . toXPath ( ) ,  `substring(@${ attrName } ${ attrName } ${ endsWith } ${ endsWith }  , 
327+     ) ; 
328+     return  new  Locator ( {  xpath } ) ; 
329+   } 
330+ 
331+   /** 
332+      * Adds condition: attribute value contains text 
333+      * (analog of XPATH: [contains(@attr,'partOfAttribute')] or CSS [attr*='partOfAttribute'] 
334+      * Example: I.click(locate('a').withAttrContains('href', 'google'))); 
335+      * Works with any attribute: class, href etc. 
336+      * @param  {string } attrName 
337+      * @param  {string } partOfAttrValue 
338+      * @returns  {Locator } 
339+      */ 
340+   withAttrContains ( attrName ,  partOfAttrValue )  { 
341+     const  xpath  =  sprintf ( '%s[%s]' ,  this . toXPath ( ) ,  `contains(@${ attrName } ${ partOfAttrValue }  ) ; 
342+     return  new  Locator ( {  xpath } ) ; 
343+   } 
344+ 
302345  /** 
303346   * @param  {String } text 
304347   * @returns  {Locator } 
0 commit comments