import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class chuangkouqiehuan20161206 {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Training\\Automation\\Software\\drivers\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.hao123.com/");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id='box-famoussite']/div/div[2]/span[2]/a")).click();
Thread.sleep(5000);
System.out.println("进入58同城");
// String[] handles=new String[driver.getWindowHandles().size()];
// driver.getWindowHandles().toArray(handles);
// driver.switchTo().window(handles[1]);
for (String handle:driver.getWindowHandles())
{
driver.switchTo().window(handle);
}
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id='nav']/li[7]/a")).click();
Thread.sleep(5000);
System.out.println("进入安居客");
// String[] handles1=new String[driver.getWindowHandles().size()];
// driver.getWindowHandles().toArray(handles1);
// driver.switchTo().window(handles1[2]);
for (String handle:driver.getWindowHandles())
{
driver.switchTo().window(handle);
}
driver.findElement(By.xpath("//*[@id='header']/div[3]/div[2]/a[1]")).click();
Thread.sleep(5000);
System.out.println("进入我要推广");
for (String handle:driver.getWindowHandles())
{
driver.switchTo().window(handle);
}
driver.findElement(By.xpath("//*[@id='footer']/ul[1]/li[11]/a")).click();
Thread.sleep(5000);
System.out.println("进入房贷计算器");
String[] handles=new String[driver.getWindowHandles().size()];
driver.getWindowHandles().toArray(handles);
driver.switchTo().window(handles[2]);
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id='search-esf']")).sendKeys("上海浦东新区张江高科");
System.out.println("回到第三个窗口进行操作");
Thread.sleep(2000);
Actions action=new Actions(driver);
// action.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).perform();
WebElement element=driver.findElement(By.xpath("//*[@id='search-esf']"));
action.click(element).keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).perform();
action.keyDown(Keys.CONTROL).sendKeys("c").keyUp(Keys.CONTROL).perform();
action.click(element).keyDown(Keys.CONTROL).sendKeys("v").keyUp(Keys.CONTROL).perform();
System.out.println("在输入框里Ctrl a,Ctrl c,Ctrl v");
}
}
|