Lutfi
Lutfi

Reputation: 7

How to select or click elements on same locator using index in robot framework

I'm currently new using robot frame framework and having issue with select or click an element with/under same locator (e.g id in this case) So, I have an element $id=search that have 4 elements (not a dropdown)

like this

I want to select one of them.

In Selenium's Java I can used like this

    List<WebElement> elem=driver.findElements(By.id(search));
    elem.get(1).click();

But can't find a way using robot framework yet.

Please advise, Thanks

Upvotes: 0

Views: 9226

Answers (2)

Crama
Crama

Reputation: 141

Using the same way as you did with Java, clicking the first element would look like this:

@{webElements} | Get Webelements | ${locator}
Click Element | @{webElements[0]}

Notice that the '[0]' needs to be within the curly brackets.

You could also use xpath as locator, which would look like this for selecting the first element with the given id:

Click Element | //*[@id='elementId'][0]

Upvotes: 3

Rakesh
Rakesh

Reputation: 1575

If you want to click the first instance of locator, then you can use as below:

 Click Element     ${Locator}[1]

Upvotes: 0

Related Questions