Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java selenium中选择具有动态id的单选按钮_Java_Selenium_Selenium Webdriver - Fatal编程技术网

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

在java selenium中选择具有动态id的单选按钮,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,如何在java selenium webdriver中选择一个附加了动态id的单选按钮。我无法事先确定附加的数字。所以我需要一种方法,通过部分匹配文本进行选择,同时忽略最后一个数字 id=edit-emergency-notification-status-existing-message-7 !!“7”与在此屏幕中创建的每个新项目一起生成通过xpath在starts-with()的帮助下获取: 尝试CSS选择器并使用以野生字符(^)开头的字符 我得到:org.openqa.selenium.

如何在java selenium webdriver中选择一个附加了动态id的单选按钮。我无法事先确定附加的数字。所以我需要一种方法,通过部分匹配文本进行选择,同时忽略最后一个数字

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

!!“7”与在此屏幕中创建的每个新项目一起生成

通过xpath在
starts-with()的帮助下获取


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


我得到:
org.openqa.selenium.InvalidSelectorException:给定的选择器[以(@id,“编辑紧急通知状态现有消息-”)开头]无效或未生成WebElement。发生以下错误:InvalidSelectorError:无法找到xpath表达式为[以(@id,“编辑紧急通知状态现有消息-”)开头]的元素由于以下错误:SyntaxError:该表达式不是合法表达式。
@3ck您确定使用的表达式与答案中的表达式完全相同吗?我在By中使用它:
private By alertRadioButton=By.xpath([以(@id,\“edit emergency notification status existing message-\”)开头)@3ck那么开头的
/*
部分呢?
//*[starts-with(@id, "edit-emergency-notification-status-existing-message-")]
driver.findElement(By.cssSelector("input[id^='edit-emergency-notification-status-existing-message']"));