package zongJie;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//加载类
public class Example {
public static void test(WebDriver driver) throws InterruptedException {
// 1.打开网页,最大化窗口。
driver.get("http://www.meituan.com");
driver.manage().window().maximize();
Thread.sleep(1000);
// 1.打开网页,最大化窗口。
// 点击,并切换到新window
driver.findElement(By.xpath("//*[@id=\"banner-slider\"]/div[1]/div[1]/a")).click();
String thisHandleId = driver.getWindowHandle();
for (String tempHandleId : driver.getWindowHandles()) {
// 如果不是当前窗口的thisHandleId,那么我们就用它取切换到新窗口
if (!tempHandleId.equals(thisHandleId)) {
driver.switchTo().window(tempHandleId);
}
}
System.out.println("当前窗口" + driver.getCurrentUrl());
System.out.println("Success--->2.通过首页的住酒店图片链接进入酒店预订页面");
Thread.sleep(500);
// 点击,并切换到新window
// 鼠标悬浮,点击隐藏菜单
Actions action = new Actions(driver);
WebElement a = driver.findElement(By.xpath("//*[@id=\"app\"]/section/section/div[2]/div[1]/div[1]/div[3]/div[5]"));
action.moveToElement(a).build().perform();
Thread.sleep(500);
action.click();
Thread.sleep(500);
WebElement a2 = driver.findElement(By.xpath("//*[@id=\"app\"]/section/section/div[2]/div[1]/div[2]/div[5]/div[1]/a[1]"));
action.moveToElement(a2).build().perform();
Thread.sleep(500);
action.click();
Thread.sleep(500);
// 鼠标悬浮,点击隐藏菜单
// 登录界面
driver.findElement(By.xpath("//*[@id=\"app\"]/section/div[2]/div[2]/form/ul/li[1]/span/input")).sendKeys("小桃呵呵");
driver.findElement(By.xpath("//*[@id=\"app\"]/section/div[2]/div[2]/form/ul/li[2]/span/input")).sendKeys("15151080083");
driver.findElement(By.xpath("//*[@id=\"app\"]/section/div[2]/div[4]/button")).click();
// 登录界面
}
// 主函数
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
try {
test(driver);
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("即将关闭ChromeDriver...");
System.out.println("三秒等待中...");
Thread.sleep(3000);
driver.quit();
System.out.println("已退出程序。。。");
}
}
// 主函数
}
// 加载类