1
votes

As part of a Robot Framework test I would like to access multiple objects from my page with the same keyword. The xpath of the objects looks like this:

//div[@class='col-sm-4 ng-scope']//h1[@class='ng-binding'][contains(text(),'Bot1')]
//div[@class='col-sm-4 ng-scope']//h1[@class='ng-binding'][contains(text(),'Bot2')]
//div[@class='col-sm-4 ng-scope']//h1[@class='ng-binding'][contains(text(),'Botx')]

I've tried to set a list variable with the name of my test objects (elements)

*** Variables ***
@{TESTBOTS} =  Bot1  Bot2  Botx

*** Keywords ***
Delete Bots
    go to  ${LANDINGURL}
    Sleep  3s
    Click Element  //div[@class='col-sm-4 ng-scope']//h1[@class='ng-binding'][contains(text(), @{TESTBOTS})]

However, I get the following error:

FAIL        Element with locator '//div[@class='col-sm-2 ng-scope']//h1[@class='ng-binding'][contains(text(),'${TESTBOTS')]' not found.

I'd really appreciate if you could point me to the right direction. Thanks!

1
You seem to be missing a keyword on the last line of Delete Bots -- you just have an xpath where a keyword should be. - Bryan Oakley
Thank Bryan! You are right. The uploaded snippet was incorrect. Here is the actual code I've tried: *** Variables *** @{TESTBOTS} = Bot1 Bot2 Botx *** Keywords *** Delete Bots go to ${LANDINGURL} Sleep 3s Click Element //div[@class='col-sm-4 ng-scope']//h1[@class='ng-binding'][contains(text(), @{TESTBOTS})] - János

1 Answers

3
votes

The error message still does not seem to fit the snippet, I believe.

But anyway: with @{TESTBOTS} you unwrap the complete list. I would have expect an error like No element found with text 'Bot1 Bot2 Botx'

I think this should work iterating the list of testbots:

FOR    ${testbot}    IN    @{TESTBOTS}
    Click Element    //div[@class='col-sm-4 ng-scope']//h1[@class='ng-binding'][contains(text(), ${testbot})] 
END