4

I need to see if the current page is displaying the correct title icon. We change the icon depending on where you are on the site, and need to make a check against it.

I have tried

Page Should Contain Image    /bin/icons/1.ico

The HTML we use is:

<link rel="shortcut icon" type="image/x-icon" href="/bin/icons/1.ico"/>

The keyword did not work.. Is there something else I have to use? or is it not supported by selenium to do this kind of test?

Goralight
  • 2,067
  • 6
  • 25
  • 40
  • 1
    have you tried getting the value of the `href` attribute with [Get Element Attribute](http://robotframework.org/Selenium2Library/Selenium2Library.html#Get%20Element%20Attribute)? – Bryan Oakley Dec 01 '16 at 13:05
  • How could I get the locator of something which isnt being displayed within the page? It is being displayed on the browser tab. – Goralight Dec 01 '16 at 13:36
  • I don't know. I'm simply asking if that's something you've tried to figure out. – Bryan Oakley Dec 01 '16 at 13:37
  • Trying to figure it out now - good suggestion – Goralight Dec 01 '16 at 13:40
  • So - after thinking about it and looking at the documentation - I used this: ${test} = get element attribute tag=link@href However, the favicon isnt the first link. It is the second. Is there a way to choose the 2nd one? similar to xpath? – Goralight Dec 01 '16 at 14:02

2 Answers2

1

According to the currently applied standards, the correct way to set the favicon is through a link tag, having rel="icon" attribute, though some sites still use rel="shortcut icon" (more details in the wikipedia link above). This xpath covers both:

${loc}=    xpath=//link[@rel="link" or @rel="shortcut icon"]

To get its value, use the normal robotframework approach:

${favicon}=    Get Element Attribute     ${loc}@href
Todor Minakov
  • 19,097
  • 3
  • 55
  • 60
  • I asked and answered this question way before i really understood Xpath - and I agree - my response was very... unintuitive ;). I guess what I was trying to say was look for the Link which contains the Favicon and compare it to the expected link. Your response is clearer and make more sense than my response. – Goralight Mar 27 '17 at 08:04
  • Glad to help @Goralight. Btw, in your solution, I'd further suggest not to go for "should be equal", rather - should contain, and look for the path after the hostname - "/bin/icons/1.ico"; thus the case will be applicable to other environments/deployments. – Todor Minakov Mar 27 '17 at 09:00
0

Figured it out. I basically grab the href of the link tag in question, and then compare them using the "should be equal as strings" keyword. I would have solved it sooner, but the icon link tag was not the first link tag. Below is the lines I used:

${Favicon1} =   Get Element Attribute    //link[2]@href
Should Be Equal As Strings    ${Favicon1}    http://localhost:8080/bin/icons/1.ico

Many thanks to Bryan Oakley for nudging me in the right direction.

Goralight
  • 2,067
  • 6
  • 25
  • 40
  • Don't do that, for two reasons. First - you probably wanted the 2nd link element - but that can easily change in a future version or build. Second, in xpath the indexing is of higher precedence than relation, so the locator actually reads "get any link, which is the 2nd child of its parent" (trust me, though unintuitive at first, it really does :). – Todor Minakov Mar 26 '17 at 19:38