0
votes

Line 1 there does find the selector

Wait Until Element Is visible  xpath=//a[contains(text(),'Download selected certificate')]

Then when i try to get the href element

${url}=    Get Element Attribute   xpath=//a[contains(text(),'Download selected certificate')]/@href

It fails Error says

InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //a[contains(text(),'Download selected certificate')]/ because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[contains(text(),'Download selected certificate')]/' is not a valid XPath expression.

Im not sure why as i have a working unrelated example with similar syntax

${url}=    Get Element Attribute   xpath=//tr[contains(b/span, Jul)][${row_number}]/td[5]/span/a/@href
1

1 Answers

1
votes

In xpath, a value of //a[contains(text(),'Download selected certificate')]/@href would return an object which is the href attribute of that a tag.

In Selenium2Library though, when calling Get Element Attribute, @ designates the attribute name to get the value of, for a particular dom elelement.
So what that keyword does is to split that string on the last @, get a webelement on the 1st part, and retrieve the target attribute's (the 2nd part of the split) value.
Doing so, it ends up with a locator for the element being //a[contains(text(),'Download selected certificate')]/ - and that trailing / makes it an invalid xpath.

The solution is simple - lose the trailing slash; e.g.:

${url}=    Get Element Attribute   xpath=//a[contains(text(),'Download selected certificate')]@href

As for why your last sample works - it beats me too :)