0

I got an id that keeps changing each time my page refreshes i tried using

start-with@id
contains@id

//*[@id="mat-input-2"] the 2 after the input changes each time i refresh the page I've tried everyting

everytime when I try someting new i get errors like this.

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[starts-with(@id="mat-input-")]' is not a valid XPath expression

I have googled everywhere tried everyting i don't know what else to do so my last resort is trying this forum

Thank you for your help have a nice day

dimay
  • 2,768
  • 1
  • 13
  • 22

2 Answers2

1

This error message...

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[starts-with(@id="mat-input-")]' is not a valid XPath expression

...implies that the which you have used was not a valid XPath expression.

Seems you were almost there. You just need to replace the = character with , character to make it a valid xpath expression you can use either of the following Locator Strategies:

  • Using xpath and starts-with():

    //*[starts-with(@id, "mat-input-")]
    
  • Using xpath and contains():

    //*[contains(@id, "mat-input-")]
    
  • Using cssSelector and starts-with:

    [id^='mat-input-']
    
  • Using cssSelector and contains:

    [id*='mat-input-']
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You used it incorrectly. It should be

'//*[starts-with(@id, "mat-input-")]'

Note comma instead of equal sign

P.S. Same for contains

DonnyFlaw
  • 581
  • 3
  • 9