我在网站上有一个表格,我需要检查是否使用Selenium来满足要求。
行数是动态的 - 一天是3天,一天是5行。 如果当前值(大于或等于最小值)和(小于或等于每行中的最大值),我想写一个检查(比较数字)的方法即可。
我写了这个方法,但它只适用于一行并且只检查最小值。
代码
@FindBy(xpath = "//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[1]/td[3]")
protected WebElement minimumREQ1;
@FindBy(xpath = "//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[1]/td[4]")
protected WebElement actualREQ1;
@FindBy(xpath = "//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[1]/td[5]")
protected WebElement maximumREQ1;
public void checkRow1() {
if (minimumREQ1.isDisplayed()) {
for (int i = 1; i < 10; i += 1) {
String ov1 = minimumREQ1.getText();
String ov2 = actualREQ1.getText();
String ov3 = maximumREQ1.getText();
if (ov1.equals("-")) { ov1 = "0"; }
if (ov2.equals("-")) { ov2 = "0"; }
if (ov3.equals("-")) { ov3 = "0"; }
double doubleOV1 = Double.parseDouble(ov1);
double doubleOV2 = Double.parseDouble(ov2);
double doubleOV3 = Double.parseDouble(ov3);
if (doubleOV2 < doubleOV1) {
Integer number = firstnumber + i;
String stringNumber = number.toString();
increaseProduct1.clear();
increaseProduct1.sendKeys(stringNumber);
} else {
break;
}
答案 0 :(得分:0)
试试这个。
List<WebElement> webElement =
driver.findElements(By.xpath("//table[@class="qor-table"]//tbody/tr"));
for (int i = 1;i<=webElement.size();i++){
System.out.println("Minimum "+driver.findElement(By.xpath("//table[@class="qor-
table"]//tbody/tr["+i+"]/td[3]")));
System.out.println("Current "+driver.findElement(By.xpath("//table[@class="qor-
table"]//tbody/tr["+i+"]/td[4]")));
System.out.println("Maximum "+driver.findElement(By.xpath("//table[@class="qor-
table"]//tbody/tr["+i+"]/td[5]")));
}
希望这有帮助!
答案 1 :(得分:0)
好的,我自己设法做到这一点。
public void checkQOR() {
int rowCount = driver.findElements(By.xpath("//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr")).size();
for (int j = 1; j <= rowCount; j++) {
for (int i = 1; i < 100; i++) {
WebElement elementMIN = driver.findElement(By.xpath("//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[" + j + "]/td[3]"));
wait.until(ExpectedConditions.visibilityOf(elementMIN));
double doubleMIN = Double.parseDouble(elementMIN.getText().replaceAll("-", "0"));
WebElement elementCUR = driver.findElement(By.xpath("//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[" + j + "]/td[4]"));
wait.until(ExpectedConditions.visibilityOf(elementCUR));
double doubleCUR = Double.parseDouble(elementCUR.getText().replaceAll("-", "0"));
WebElement elementMAX = driver.findElement(By.xpath("//*[@id=\"po-carts\"]/div[1]/div/table/tbody/tr[" + j + "]/td[5]"));
wait.until(ExpectedConditions.visibilityOf(elementMAX));
double doubleMAX = Double.parseDouble(elementMAX.getText().replaceAll("-", "0"));
if ( doubleMIN > 0 && doubleCUR < doubleMIN && (doubleCUR < doubleMAX || doubleMAX==0 )) {
Integer number = firstnumber + i;
String stringNumber = number.toString();
wait.until(ExpectedConditions.visibilityOf(increaseProduct1));
increaseProduct1.clear();
increaseProduct1.sendKeys(stringNumber);}
else if (doubleMAX > 0 && doubleCUR > doubleMAX) {
//DO SMTH
}
else {
break;
}
}
}
}