标签:als pack selenium gettime image sendkeys logs for bdr
接上一篇,我们依然以京东的网站做示例。
三,单选项
下面来做这样一条case:
1. 登录京东旅行网页。
2. 在国内机票板块,购买从北京到武汉的往返机票,时间为明天出发,一周后返回。
3.搜索机票。
示例代码:
package JD_Practice; import java.text.SimpleDateFormat; import java.util.Calendar; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class SeleniumAction_RadioButton { private static WebDriver driver; private static String baseUrl; public static void main(String[] args) { driver=new FirefoxDriver(); baseUrl="http://jipiao.jd.com/"; driver.get(baseUrl); driver.manage().window().maximize(); PlainTravel_RadioButton(driver); //driver.quit(); } public static void PlainTravel_RadioButton(WebDriver dr){ dr.findElement(By.id("depCity")).clear(); dr.findElement(By.id("depCity")).sendKeys("±±??"); dr.findElement(By.id("arrCity")).clear(); dr.findElement(By.id("arrCity")).sendKeys("??oo"); dr.findElement(By.id("roundFlight")).click(); Calendar cal2= Calendar.getInstance(); SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd"); String CurrentDate = f.format(cal2.getTime()); String StartDate = String.valueOf((Integer.valueOf(CurrentDate)+1)); String RoundDate = String.valueOf((Integer.valueOf(CurrentDate)+7)); System.out.println(CurrentDate); System.out.println(StartDate); System.out.println(RoundDate); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.getElementById(‘depDate‘).readOnly=false;"); dr.findElement(By.id("depDate")).clear(); dr.findElement(By.id("depDate")).sendKeys(StartDate); js.executeScript("document.getElementById(‘arrDate‘).readOnly=false;"); dr.findElement(By.id("arrDate")).clear(); dr.findElement(By.id("arrDate")).sendKeys(RoundDate); dr.findElement(By.id("validQuery")).click(); } }
运行成功后跳转到机票页面
标签:als pack selenium gettime image sendkeys logs for bdr
原文地址:http://www.cnblogs.com/AryaZ/p/7640624.html