我正在学习使用TestNG进行自动化测试。我正在尝试从日期选择器设置值日期。但是我越来越错误了。谁能帮我这个忙。
TestNG
public void Start() throws ParseException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver = new ChromeDriver();
driver.get(baseUrl);
driver.findElement(By.xpath("//*[@id=\"add-edit-form\"]/div[3]/div[1]")); //location of calendar field
driver.findElement(By.id("Contract_s_date")).click();
String setDtStr="03/05/2019";
String curDateStr = driver.findElement(By.className("dtp-date")).getText();
Date setDate=new SimpleDateFormat("dd/MM/yyyy").parse(setDtStr);
Date curDate=new SimpleDateFormat("MMMM yyyy").parse(curDateStr);
int monthDiff = Months.monthsBetween(new DateTime(curDate).withDayOfMonth(1),new DateTime(setDate).withDayOfMonth(1)).getMonths();
boolean isFuture = true;
if (monthDiff < 0) {
isFuture= false;
monthDiff = -1 * monthDiff;
}
for(int i=0; i<monthDiff;i++)
{
if(isFuture)
{
driver.findElement(By.xpath("//*[@id=\"dtp_KoRH3\"]/div/div[1]/div[1]/div[1]/div[3]/a")).click(); // Anchor tag for next button
}else {
driver.findElement(By.xpath("//*[@id=\"dtp_KoRH3\"]/div/div[1]/div[1]/div[1]/div[1]/a")).click(); //anchor tag for previous button
}
}
}
错误
Unknown error: Element <input class="form-control" id="Contract_s_date" name="Contract_s_date" type="text" value="" data-dtp="dtp_wvocN"> is not clickable at point (216, 227). Other element would receive the click: <div class="preloader" style="opacity: 0.91354;">...</div>