我对硒很陌生。我希望通过从本地excel表中获取数据,使用selenium在我的网页中选择复选框。对于所有的单选按钮,我都做到了这一点,但是我想选择的这些复选框没有'id‘属性。它们仅以“价值”来区别。
HTML代码是:
<input type="hidden" value="1" name="%%Surrogate_Competitors"/>
<label>
<input type="checkbox" title="Competitors" value="HP (Servers)" name="Competitors"/>
HP (Servers)
</label>
<br/>
<label>
<input type="checkbox" title="Competitors" value="Sun (Servers)" name="Competitors"/>
Sun (Servers)
</label>
<br/>
<label>
<input type="checkbox" title="Competitors" value="HP (Storage)" name="Competitors"/>
HP (Storage)
</label>
<br/>
............
............我试着使用这段代码来选择这些复选框:
String Competitors=sh.getCell(column,1).getContents();
String delims = "[,]";
String[] Competitor = Competitors.split(delims);
for(int i=0;i<Competitor.length;i++) {
//to select competitors
driver.findElement(By.cssSelector("input[value="+Competitor[i]+"]")).click();
}当我运行此代码时,将生成如下错误消息:
给定的选择器inputvalue=HP (存储)要么无效,要么不会导致WebElement。
请让我知道如何克服这一点,并使复选框被选中。
发布于 2016-03-21 10:29:59
请检查css标识符,您可能需要为值添加引号:
driver.findElement(By.cssSelector("input[value='" + Competitor[i] + "']"))这个stack post一定很有用
https://stackoverflow.com/questions/36127341
复制相似问题