我的动作课如下
public class NewUserFormAction {
public static void Execute(WebDriver driver,List<HashMap<String,String>> map) throws Exception{
abstract class CalendergetDropdown{
// get a select dropdown list
public Select getSelectOptionsDay() {
return new Select(NewUserFormPage.Calandersection.day_dropdownList);
}
public Select getSelectOptionsMonth() {
return new Select(NewUserFormPage.Calandersection.month_dropdownList);
}
public Select getSelectOptionsYear() {
return new Select(NewUserFormPage.Calandersection.years_dropdownList);
}
// Set the calender values
public void setDayoption(String day) {
getSelectOptionsDay().selectByValue(dateOfBirth);
}
public void setMonthoption(String month) {
getSelectOptionsMonth().selectByValue(monthOfBirth);
}
public void setYearoption(String year) {
getSelectOptionsYear().selectByValue(yearOfBirth);
}
}
我受到警告以下的警告,因此我的代码无法从日/月/年下拉菜单中选择该值。让我知道在POM中执行select时是否缺少任何内容。
我找到了解决此问题的方法,未在newuserAction类中创建父类newuserformpage的对象引用,因此向对象发出警告。下面是解决此问题的代码。
NewUserFormAction actionForm = new NewUserFormAction();
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.elementToBeClickable(NewUserFormPage.gender));
NewUserFormPage.gender.click();
NewUserFormPage.customer_firstname.sendKeys(actionForm.name);
NewUserFormPage.customer_lastname.sendKeys(actionForm.Surname);
NewUserFormPage.password_new_cust.sendKeys("password");
Select selectDate = new Select(NewUserFormPage.Calandersection.day_dropdownList);
selectDate.selectByValue(dateOfBirth);
Select selectMonth = new Select(NewUserFormPage.Calandersection.month_dropdownList);
selectMonth.selectByVisibleText(monthOfBirth);
Select selectYear = new Select(NewUserFormPage.Calandersection.years_dropdownList);
selectYear.selectByVisibleText(yearOfBirth);