我想从Excel工作表导入数据,并将其传递到Xpath的一部分。有什么办法可以做到呢?请给我建议一些我可以实现的方式。我尝试使用以下代码:
String size = sheet.getRow(24).getCell(1).getStringCellValue();
String s = driver.findElement(By.xpath("//div[contains(text(),size)]/input[@type='radio']")).getAttribute(size);
System.out.println(s);
在这里我想要的是从excel导入数据,我将其存储在变量'size'中,而我在xpath的某些部分中需要此size变量。我尝试使用此变量,但其打印为null。
如发布的那样,size
被识别为字符串文字"size"
。您想连接字符串:
String size = sheet.getRow(24).getCell(1).getStringCellValue();
String query = "//div[contains(text(),'" + size + "')]/input[@type='radio']";
String s = driver.findElement(By.xpath(query)).getAttribute(size);
System.out.println(s);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句