Search code examples
htmlseleniumsalesforceui-automationsalesforce-lightning

How can i locate/ code in selenium to identify different radio button which belong to same class ,<span> html tag and has no unique identifier?


I am working with automation of the Standard Cases Object in salesforce app. There are different types of cases corresponding to each radio group. there is no unique identifier for the same. How can i locate the radio button?

I cannot use the (.contain()) attribute as there is no label connected to radio button tag. both of the span tags below belong to same tag.

and there are different radio buttons in the div tag.

(this is radio button) Label (this is the radio button label)


Solution

  • If all elements have same locators (for multiple matches) we could use findElements method to get all the matches and as we get list of WebElement as return type then can access the required one using index.

    List<WebElement> elementList=driver.findElements(By.xpath("locator"));
    

    Once we have the list we could use index or could apply other iteration techniques in list as per our requirement to access the webelement.

    WebElement firstElement=elementList.index(0);
    element.click();