public class AddEmployee2 {
public static void main(String[] args) throws Exception {
String dateTime ="26/02/1989";
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://testing-1/Premium_Next_03June2016/default.aspx");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.findElement(By.id("txtUsername")).sendKeys("Super");
driver.findElement(By.id("txtPassword")).sendKeys("sa");
driver.findElement(By.id("btnLogin")).click();
Actions act = new Actions(driver);
/* Find the xpath of File menu*/
WebElement element = (driver.findElement(By.xpath("id('maintext-1')")));
act.moveToElement(element).perform();
driver.findElement(By.xpath(".//*[@id='subtext-1-10']/span")).click();
driver.findElement(By.id("_ctl0_MainBody_cmdNew")).click();
driver.findElement(By.id("_ctl0_MainBody_txtCode")).sendKeys("501");
driver.findElement(By.id("_ctl0_MainBody_txtName")).sendKeys("Rahul");
//button to open calendar
WebElement selectDate = driver.findElement(By.xpath(".//*[@id='_ctl0_MainBody_txtDOB_TextDatepicker']"));
selectedDate.click();
WebElement nextLink = driver.findElement(By.xpath("//div[@id='_ctl0_MainBody_txtDOB_TextDatepicker_CalendarExtender_nextArrow']"));
WebElement midLink = driver.findElement(By.xpath("//div[@id='_ctl0_MainBody_txtDOB_TextDatepicker_CalendarExtender_title']"));
WebElement previousLink = driver.findElement(By.xpath(" //div[@id='_ctl0_MainBody_txtDOB_TextDatepicker_CalendarExtender_prevArrow']"));
String date_dd_MM_yyyy[] = (dateTime.split(" ")[0]).split("/");
int yearDiff = Integer.parseInt(date_dd_MM_yyyy[2])- Calendar.getInstance().get(Calendar.YEAR);
System.out.println("Test"+Integer.parseInt(date_dd_MM_yyyy[2]));
System.out.println("what is this"+Calendar.getInstance().get(Calendar.YEAR));
System.out.println("Year difference Ram"+yearDiff);
midLink.click();
if(yearDiff!=0){
//if you have to move next year
if(yearDiff>0){
for(int i=0;i< yearDiff;i++){
System.out.println("Year Diff next->"+i);
nextLink.click();
}
}
//if you have to move previous year
else if(yearDiff<0){
for(int i=0;i< (yearDiff*(-1));i++){
System.out.println("Year Diff previous->"+i);
previousLink.click();
}
Thread.sleep(1000);
//Get all months from calendar to select correct one
List<WebElement> list_AllMonthToBook = driver.findElements(By.xpath("//div[@id='_ctl0_MainBody_txtDOB_TextDatepicker_CalendarExtender_months']//table[@id='_ctl0_MainBody_txtDOB_TextDatepicker_CalendarExtender_monthsTable']//tbody[@id='_ctl0_MainBody_txtDOB_TextDatepicker_CalendarExtender_monthsBody']"));
list_AllMonthToBook.get(Integer.parseInt(date_dd_MM_yyyy[1])-1).click();
// System.out.println("Get all Months"+(Integer.parseInt(date_dd_MM_yyyy[1])-1));
Thread.sleep(1000);
//get all dates from calendar to select correct one
List<WebElement> list_AllDateToBook = driver.findElements(By.xpath("//div[@id='datetimepicker_dateview']//table//tbody//td[not(contains(@class,'k-other-month'))]"));
list_AllDateToBook.get(Integer.parseInt(date_dd_MM_yyyy[0])-1).click();
}
}
例外:螺紋我得到下面的代碼錯誤硒
異常 「主要」 java.lang.IndexOutOfBoundsException:指標:1,大小:1在java.util中。 ArrayList.rangeCheck(未知來源)在java.util.ArrayList.get(未知來源)在eMpower.AddEmployee2.main(AddEmployee2.java:109)
異常線程 「main」 java.lang.IndexOutOfBoundsException:指標:1,尺寸:1 \t在java.util.ArrayList.rangeCheck(來源不明) \t在java.util中.ArrayList.get(來源不明) \t在eMpower.AddEmployee2.main(AddEmployee2.java:109) –
哪條線是109? – MordechayS
並請添加例外在你的問題...... – MordechayS