Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选择特定日期jQuery UI日期选择器_Jquery_Selenium_Datepicker - Fatal编程技术网

选择特定日期jQuery UI日期选择器

选择特定日期jQuery UI日期选择器,jquery,selenium,datepicker,Jquery,Selenium,Datepicker,如何从jQueryUIDatePicker中选择特定日期?例如,我需要将当前日期选择为(“开始日期””),将当前日期的一周选择为(“结束日期”)。 日期选择器仅包含当前月份的天数 去打开日历和时钟的地方,然后根据要求的日期和时间进行迭代 我希望下面的代码为您工作 导入java.util.Calendar 导入java.util.List 导入java.util.concurrent.TimeUnit 导入org.openqa.selenium.By 导入org.openqa.selenium.W

如何从jQueryUIDatePicker中选择特定日期?例如,我需要将当前日期选择为(“开始日期””),将当前日期的一周选择为(“结束日期”)。
日期选择器仅包含当前月份的天数

去打开日历和时钟的地方,然后根据要求的日期和时间进行迭代

我希望下面的代码为您工作

导入java.util.Calendar

导入java.util.List

导入java.util.concurrent.TimeUnit

导入org.openqa.selenium.By

导入org.openqa.selenium.WebDriver

导入org.openqa.selenium.WebElement

导入org.openqa.selenium.firefox.FirefoxDriver

导入org.testng.annotations.Test

公共类日期选择器{

@Test

public void testDAtePicker() throws Exception{

    //DAte and Time to be set in textbox

    String dateTime ="12/07/2014 2:00 PM";

    WebDriver driver = new FirefoxDriver();

    driver.manage().window().maximize();

    driver.get("http://demos.telerik.com/kendo-ui/datetimepicker/index");

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //button to open calendar

    WebElement selectDate = driver.findElement(By.xpath("//span[@aria-controls='datetimepicker_dateview']"));

selectDate.click();

//button to move next in calendar

WebElement nextLink = driver.findElement(By.xpath("//div[@id='datetimepicker_dateview']//div[@class='k-header']//a[contains(@class,'k-nav-next')]"));

//button to click in center of calendar header

WebElement midLink = driver.findElement(By.xpath("//div[@id='datetimepicker_dateview']//div[@class='k-header']//a[contains(@class,'k-nav-fast')]"));

//button to move previous month in calendar

WebElement previousLink = driver.findElement(By.xpath("//div[@id='datetimepicker_dateview']//div[@class='k-header']//a[contains(@class,'k-nav-prev')]")); 

    //Split the date time to get only the date part

    String date_dd_MM_yyyy[] = (dateTime.split(" ")[0]).split("/");

    //get the year difference between current year and year to set in calander

    int yearDiff = Integer.parseInt(date_dd_MM_yyyy[2])- Calendar.getInstance().get(Calendar.YEAR);

    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->"+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->"+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='datetimepicker_dateview']//table//tbody//td[not(contains(@class,'k-other-month'))]"));

    list_AllMonthToBook.get(Integer.parseInt(date_dd_MM_yyyy[1])-1).click();

    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();

    ///FOR TIME

    WebElement selectTime = driver.findElement(By.xpath("//span[@aria-controls='datetimepicker_timeview']"));

    //click time picker button

    selectTime.click();

    //get list of times

    List<WebElement> allTime = driver.findElements(By.xpath("//div[@data-role='popup'][contains(@style,'display: block')]//ul//li[@role='option']"));

    dateTime = dateTime.split(" ")[1]+" "+dateTime.split(" ")[2];

 //select correct time

    for (WebElement webElement : allTime) {

        if(webElement.getText().equalsIgnoreCase(dateTime))

        {

            webElement.click();

        }

    }

}
@测试
public void testDAtePicker()引发异常{
//要在文本框中设置的日期和时间
字符串dateTime=“2014年7月12日下午2:00”;
WebDriver=newfirefoxdriver();
driver.manage().window().maximize();
驱动程序。获取(“http://demos.telerik.com/kendo-ui/datetimepicker/index");
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
//打开日历的按钮
WebElement selectDate=driver.findElement(By.xpath(//span[@aria controls='datetimepicker\u dateview']);
选择日期。单击();
//在日历中移动下一步的按钮
WebElement nextLink=driver.findElement(By.xpath(“//div[@id='datetimepicker\u dateview']//div[@class='k-header']///a[contains(@class,'k-nav-next')]);
//单击日历标题中心的按钮
WebElement midLink=driver.findElement(By.xpath(“//div[@id='datetimepicker\u dateview']//div[@class='k-header']]//a[contains(@class,'k-nav-fast')]);
//在日历中移动上个月的按钮
WebElement previousLink=driver.findElement(By.xpath(“//div[@id='datetimepicker\u dateview']//div[@class='k-header']///a[contains(@class,'k-nav-prev')]);
//拆分日期时间以仅获取日期部分
字符串date\u dd\u MM\u yyyyy[]=(dateTime.split(“”[0]).split(“”/“”);
//获取当前年份与要在日历中设置的年份之间的年份差
int yearDiff=Integer.parseInt(date_dd_MM_yyyy[2])-Calendar.getInstance().get(Calendar.YEAR);
midLink.click();
如果(年差!=0){
//如果你明年要搬家的话
如果(年差>0){
对于(int i=0;i”+i);
单击();
}
}
//如果你上一年不得不搬家

else if(YearDiff)请共享处理日期操作的脚本,并通过此链接共享datepickerGo的源代码。希望这会有所帮助。