标签:
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