我正在尝试传递一个i值来获取带有动态ID的随机选择复选框,并在下面粘贴代码并显示相应的错误消息。
By.xpath("//div[contains(@id,'team_"+randNumber(i)+")]")) != null){
错误显示为:
The given selector //div[contains(@id,'team_'2)] is either invalid or does not result in a WebElement.
因此,上述术语必须显示为//div[contains(@id,'team_2')]
答案 0 :(得分:1)
这与
int rand = randNumber(i);
String id = "team_" + rand;
String xpathh = "//div[contains(@id, '" + id + "']"; // note the nested quotes!
By.xpath(xpathh));
如果您想将其转换为一行,请将所有内容复制到一起产生:
By.xpath("//div[contains(@id, '" + "team_" + randNumber(i) + "']"));
可以优化几个引号:
By.xpath("//div[contains(@id, 'team_" + randNumber(i) + "']"));
答案 1 :(得分:0)
应该是这样的:
By.xpath("//div[contains(@id,'team_"+randNumber(i)+"')]")