3

In my RF-Selenium project I have a language selection with a couple different options to choose from, which I locate through xpath. I usually separate my high-level keywords, locators/global variables and tests in 3 different files, so I need to get the xpath in one file and keywords in other.

The xpath that I tested and works when hardcoded looks like this: //select[@id="language"]/option[@value="?hl=es"] (and then change the 'es' to any other language identifier to locate other options). So, following the suggestions here I built a "GET LOCATOR" keyword to take a language identifier as a parameter and return the correct xpath:

GET LOCATOR
  [Arguments]                         ${language}
  ${option locator}                   Replace String  ${LANG}  placeholder  ${language}
  [Return]                            ${option locator}

I have two different keywords that would use the return value from the GET LOCATOR keyword: in one of them I verify the currently selected language is disabled in the selection list:

  ${current}                          Get Element Attribute  html@lang
  Element Should Be Disabled          GET LOCATOR  ${current}

and then I actually select a different language and check the page has switched to it:

  Select From List By Value           ${LANGUAGE SWITCH}  es
  Wait Until Page Contains Element    GET LOCATOR  'es'

All of these is in the Resources file, while the ${LANGUAGE SWITCH} and ${LANG} variables are in a different file (and the Replace String keyword is in the String RF standard library).

The ${LANGUAGE SWITCH} variable holds a css selector that successfully locates the language dropdown. And I already did some tests without the GET LOCATOR keyword and they passed, like:

${current}                    Get Element Attribute  html@lang
Element Should Be Selected    xpath=//select[@id="language"]/option[@value="?hl=${current}"]

So I suspect there's a problem with my placeholder xpath, stored in the ${LANG} variable: xpath = //select[@id="language-switch"]/option[@value="?hl=placeholder"]

And this is the DOM part with the language selection dropdown:

<select id="language">
    <option value="?hl=ar">Arabic</option>
    <option value="?hl=zh-TW">Chinese (Traditional)</option>
    <option value="?hl=nl">Dutch - Nederlands‎</option>
    <option value="?hl=en" selected="" disabled="">English</option>
    <option value="?hl=el">Greek</option>
    <option value="?hl=es">Spanish‎</option>
</select>

To make things worse, the test using this keyword fails with no error message, as I only get:

| FAIL |
en

So... what am I doing wrong here?

Floella
  • 1,279
  • 1
  • 22
  • 41

1 Answers1

3

You cannot call a second keyword from Element should be disabled and Wait Until Page Contains Element. What is happening is that Element should be disabled thinks the locator is the string GET LOCATOR (which obviously doesn't exist), and the custom error message is es.

You will need to break that down into two steps:

${locator}=  GET LOCATOR  ${current}
Element should be disabled  ${locator}
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685