【发布时间】:2017-06-09 22:08:07
【问题描述】:
我需要选择具有相同 ID 的复选框 HTML:
<label class="table-checkbox-label" for="record-12034">
<input id="record-12034" class="table-checkbox" type="checkbox"/>
</label>
</td>
<td>91363007</td>
<td>EC4N</td>
<td>true</td>
<td>ACTIVE</td>
</tr>
<tr data-id="12201">
<td>
<label class="table-checkbox-label" for="record-12201">
<input id="record-12201" class="table-checkbox" type="checkbox"/>
</label>
</td>
list of checkboxes。 我会将合同 ID 发送到合同 ID 下面的过滤框,就像一个自动完成框。所以它会根据输入给出结果。 like this 但在这里我的硒代码是单击复选框列表中的第一个复选框,如图 1 所示。
请给点建议
编辑: : 关键字函数代码:
public void filter(String objectName,String testData) throws InterruptedException,IOException {
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='content']/div[7]/table/thead/tr[2]/td[2]/input")));//wait for textbox
driver.findElement(By.xpath(".//*[@id='content']/div[7]/table/thead/tr[2]/td[2]/input")).sendKeys(testData);//send data to textbox
System.out.print("Text box is now visible");
driver.findElement(By.xpath(".//*[starts-with(@id,'record')]")).click();//click on checkbox
driver.findElement(By.xpath(".//*[@id='content']/div[7]/table/thead/tr[2]/td[2]/input")).clear();//clear textbox
}
excel文件读取代码:
public void ASRTaccounts() throws IOException, InterruptedException, EncryptedDocumentException, InvalidFormatException, AWTException {
keyword = new keywords();
List<String> data = new ArrayList<String>();
File file = new File("C:\\RDMT test\\rdmt_test\\RDMT_\\LeadSuite.xlsx");
Workbook workbook = WorkbookFactory.create(file);
DataFormatter formatter = new DataFormatter();
Sheet sheet = workbook.getSheet("login");
for (Row row : sheet) {
for (Cell cell : row) {
data.add(formatter.formatCellValue(cell));
}
}
System.out.println(data);
for (int i=3;i<data.size();i++){
if (data.get(i).equals("filter")){
String key = (String) data.get(i);
String testData = (String) data.get(i+1);
String objectName = (String) data.get(i+2);
System.out.println(key);
System.out.println(testData);
System.out.println(objectName);
keyword.filter(objectName,testData);
}
【问题讨论】:
-
所以问题是您没有找到正确的复选框?你能告诉我们你的代码吗?你不能做
driver.getElement(By.id("record-12034"))或类似的事情吗? -
@ToddSewell 我正在使用我正在使用 Apache POI 的 Excel 文件将合同 ID 发送到文本框。我有一组数据要发送,我需要选中复选框,然后需要清除过滤器框。
-
@LolCoder아카쉬 我尝试过使用 xpath 开始,列表被选中。问题是它正在选择复选框,但在我将值发送到文本框之前,也是第一个复选框。
-
我提出的解决方案有什么问题?再说一次,你的 Java 代码在哪里?
-
@ToddSewell 这是我的代码,它运行良好,只有我不知道之后它开始表现得像这个问题。我已经为关键字函数添加了有问题的代码并读取了 excel 文件。
标签: java selenium selenium-webdriver automated-tests