user3303266
user3303266

Reputation: 371

RobotFramework: Finding Xpath containing text

So my link at the below location contains the words 'Download certificate'

xpath=//*[@id="training_list_table"]/tbody/tr/td[5]/span/a/text()

I want to be more specific in my search so that it doesn't just accept any old text so something like...

xpath=//*[@id="training_list_table"]/tbody/tr/td[5]/span/a/text()='Download certificate'

But this lets me down. What is the correct syntax to do such a search?

Upvotes: 2

Views: 11107

Answers (3)

Wagner Ediel
Wagner Ediel

Reputation: 1

Ok, try this:

xpath=//*[@id="training_list_table"]/tbody/tr/td[5]/span/a[@text='Download certificate']

Upvotes: 0

Andersson
Andersson

Reputation: 52665

If you want to match link that

  • contains text "Download certificate" you might use

    //a[contains(., "Download certificate")]
    
  • starts with text "Download certificate":

    //a[starts-with(., "Download certificate")]
    
  • has exact text "Download certificate":

    //a[.="Download certificate"]
    

If there are more than one link that contains "Download certificate" in a table you might specify appropriate ancestor by specific attribute, text or index, e.g. //td[5]//a[.="Download certificate"]- you don't have to include group of ancestors in your XPath like .../tbody/tr/td[5]/span/...

Upvotes: 2

user8166432
user8166432

Reputation: 11

If I understand correctly, you could try something like this:

xpath=//*[@id="training_list_table"]/tbody/tr/td[5]/span/a[contains(text(), 'Download certificate')]

//*[contains(text(), '')] is the key..

Upvotes: 1

Related Questions