在java selenium中选择具有动态ID的单选按钮

时间:2015-02-20 00:10:18

标签: java selenium selenium-webdriver

如何在java selenium webdriver中选择具有附加动态ID的单选按钮。我没有能力事先确定附加的数字。所以我需要一种方法来选择通过部分匹配的文本而忽略最后一个数字。

id=edit-emergency-notification-status-existing-message-7

!在此屏幕1

中创建的每个新项目都会生成“7”

2 个答案:

答案 0 :(得分:2)

借助starts-with()

获取 xpath
//*[starts-with(@id, "edit-emergency-notification-status-existing-message-")]

答案 1 :(得分:1)

尝试使用CSS选择器并使用带有野生字符的开头(^)

driver.findElement(By.cssSelector("input[id^='edit-emergency-notification-status-existing-message']"));