在硒webdriver我想用java/if條件。每個步驟都需要點擊,並且需要執行一次。使用Number_Select.NumberRandom(driver,2).click()的條件; = numberRandom中if else語句的選擇2。例如,所以我的問題是一旦測試用例運行它只會點擊一個數字,假設點擊2個隨機數字。請告知如何在硒webdriver中使用if/else條件與onclick?
的TestCase:
@Test(description = "Login Page Test" , enabled = true)
public void faaaa() throws Exception {
try{
driver = new FirefoxDriver();
SignIn_Action.Execute(driver);
Menu_Select.Menu_Selection(driver, 2).click();
MenuLottery_Select.Menu_Selection(driver, 1).click();
MenuSubTab_Select.MenuSubTab_1(driver, 3).click();
Number_Select.NumberRandom(driver, 2).click();
//SignIn_Action.Logout_Session(driver);
//Log.info("Login Successful");
}catch (Exception e){
System.out.println("Test 1");
//Log.error(e.getMessage());
throw (e);
}
}
Number_Select:
public static WebElement NumberRandom(WebDriver driver, int selection)
throws Exception {
if (selection == 1) {
Thread.sleep(1500);
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl/dd/i[8]"));
} else if (selection == 2) {
Thread.sleep(1500);
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[1]/dd/i[8]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[2]/dd/i[3]"));
} else if (selection == 3) {
Thread.sleep(1500);
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[1]/dd/i[8]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[2]/dd/i[3]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[3]/dd/i[5]"));
} else if (selection == 4) {
Thread.sleep(1500);
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[1]/dd/i[8]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[2]/dd/i[3]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[3]/dd/i[5]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[4]/dd/i[1]"));
} else if (selection == 5) {
Thread.sleep(1500);
element = driver.findElement(By.xpath("//*[@id='lottery']/div[3]/dl[1]/dd/i[8]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[2]/dd/i[3]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[3]/dd/i[5]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[4]/dd/i[1]"));
element = driver.findElement(By
.xpath("//*[@id='lottery']/div[3]/dl[5]/dd/i[9]"));//*[@id="lottery"]/div[3]/dl[1]/dd/i[1]
} else {
Log.error("Unable to select product list");
System.out.println("Unable select product list");
}
return element;
}
不太明白你想要什麼?然而,我很困惑你在每種情況下設置元素的方式。只有最後一個元素是有效的,可以返回。 –