0

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

1
  • Can you add the actual HTML code? This image is not really helpful to help you with the best locator option for your situation. Commented Oct 30, 2017 at 18:52

2 Answers 2

3

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] 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Crama, it worked! I confused how to call the index [0] for long. Apparently just need to insert the [0] inside curly brackets :)
0

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

 Click Element ${Locator}[1] 

1 Comment

hi rakesh, Thanks for your advise, but can you be more detailed? I've tried this ${locator} get webelements id=search click element ${locator}[2] but I get this error ValueError: Element locator with prefix '[<selenium.webdriver.remote.webelement.WebElement (session' is not supported

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.