码迷,mamicode.com
首页 > 其他好文 > 详细

时间控件处理

时间:2016-06-18 12:52:10      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

package Page;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import bsh.util.Util;

public class DefectTodoElement {
    private static WebElement element = null;
// 执行时处理时间
    public static void Time(WebDriver driver) {
        // Date curTimeDate = new Date();
        ((JavascriptExecutor) driver)
                .executeScript("document.getElementById(‘dealTimeHandle‘).value =‘2016-06-02 13:34:00‘");
    }

    // 新增时发生时间
    public static void Time1(WebDriver driver) {
        Date curTimeDate = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String date = formatter.format(curTimeDate);
        ((JavascriptExecutor) driver)
                .executeScript("document.getElementById(‘dfFindTime‘).value =‘"+date+"‘");
    }

    // 点击时间控件
    public static void timeclick(WebDriver driver) throws InterruptedException {
        WebElement xf = driver.findElement(By.id("dfFindTime"));
        xf.click();
        Thread.sleep(500);
    }

    // 选择处理时间2
    public static boolean TimeNow(WebDriver driver) throws InterruptedException {
        // WebElement xf = driver.findElement(By.id("dfFindTime"));
        // xf.click();
        // Thread.sleep(1000);
        // WebElement frame =
        // driver.findElement(By.xpath("/html/body/div[3]/iframe"));

        for (int i = 1; i <= 20; i++) {
            try {
                WebElement webElement = driver.findElement(By
                        .xpath("/html/body/div[" + i + "]/iframe"));

                driver.switchTo().frame(webElement);
                break;
            } catch (Exception e) {
                continue;
            }
        }

        Thread.sleep(500);
        driver.findElement(By.xpath("//*[@id=‘dpOkInput‘]")).click();
        driver.switchTo().defaultContent();
        return true;

    }

    protected static void waitWebElement(WebDriver driver, String xPath,
            long timeOutSecond) {
        WebDriverWait wait = new WebDriverWait(driver, timeOutSecond);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xPath)));
    }

    // 选择处理时间3
    public static void Timef(WebDriver driver) throws InterruptedException {

        // WebElement xf = driver.findElement(By.id("dfFindTime"));
        // xf.click();
        Thread.sleep(500);
        WebElement iframe = driver.findElement(By
                .xpath("/html/body/div[4]/iframe"));

        driver.switchTo().frame(iframe);
        Thread.sleep(500);
        driver.findElement(By.xpath("//*[@id=‘dpOkInput‘]")).click();
        Thread.sleep(500);
        driver.switchTo().defaultContent();
        Thread.sleep(500);

    }
}

 

时间控件处理

标签:

原文地址:http://www.cnblogs.com/cmm2016/p/5595885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!