我如何在 selenium 中定位/编码以识别属于相同 class ,<span> html 标签且没有唯一标识符的不同单选按钮?

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?

我正在使用 salesforce 应用程序中的标准案例对象自动化。每个无线电组对应不同类型的案例。 没有相同的唯一标识符。我怎样才能找到单选按钮?

我无法使用 (.contain()) 属性,因为没有标签连接到单选按钮标签。 下面的两个 span 标签属于同一个标签。

并且 div 标签中有不同的单选按钮。

(这是单选按钮) 标签 (这是单选按钮标签)

如果所有元素都具有相同的定位器(对于多个匹配项),我们可以使用 findElements 方法来获取所有匹配项,并且当我们获取 WebElement 列表时,类型为 return然后可以使用索引访问所需的。

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

一旦我们有了列表,我们就可以使用索引或者可以根据我们访问 web 元素的要求在列表中应用其他迭代技术。

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