DHP(关于alert 处理)

上一篇 / 下一篇  2012-05-14 16:30:52

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
public class DHP {
@Test(groups = { "funtest","area1","dhp"}) 
@Parameters({"baseurl"})
public void dhp () {
  
      WebDriver driver = new InternetExplorerDriver();
      String baseurl = "http://xin.msn.com/?lang=en-sg";
       driver.get(baseurl);
       try {
   Thread.sleep(3000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
      if(baseurl.indexOf("defaultz")==-1){
      driver.findElement(By.linkText("Make xinmsn my homepage")).click();
      }
      else{
       driver.findElement(By.linkText("将xinmsn设为首页")).click();
      }
     Alert alert = driver.switchTo().alert();
  if(!alert.getText().equalsIgnoreCase("Would you like to use the following as your home page?")){
   System.out.println("DHP alert not popup, pls check...");
  }
// 未完待续。。。。。。。。。。
}
}

TAG:

MillionRoses 引用 删除 dian106106   /   2012-05-15 20:24:52
常用键:
      robot = new Robot();
      robot.keyPress(KeyEvent.VK_UP);
      robot.delay(1000);
     robot.keyPress(KeyEvent.VK_UP);
      robot.delay(1000);

     robot.keyPress(KeyEvent.VK_TAB);
      robot.delay(1000);  
      robot.keyRelease(KeyEvent.VK_TAB);
      robot.delay(1000);

     robot.keyPress(KeyEvent.VK_ENTER);
        robot.delay(1000);

       robot.keyPress(KeyEvent.VK_SPACE);
        robot.delay(1000);

      robot.mouseMove(200, 50);
      robot.mousePress(InputEvent.BUTTON1_MASK);
      robot.mouseRelease(InputEvent.BUTTON1_MASK);
MillionRoses 引用 删除 dian106106   /   2012-05-15 16:47:20
将alert转成popup:
package ENSG;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.*;

public class NewTest {
@Test(groups = { "funtest","area1","dhp"})  
@Parameters({"baseurl"})
public void dhp () {               
WebDriver driver = new InternetExplorerDriver();

String overrideShowModalDialogJs="if(driver.browserbot.getCurrentWindow().showModalDialog){";

overrideShowModalDialogJs += "driver.browserbot.getCurrentWindow().showModalDialog = function( sURL, vArguments, sFeatures)";

overrideShowModalDialogJs +="driver.browserbot.getCurrentWindow().open(sURL, 'modal', sFeatures);";

overrideShowModalDialogJs += "};}";
            //showModalDialog方法进行覆盖
            //selenium.getEval(overrideShowModalDialogJs);
String baseurl = "http://xin.msn.com/?lang=en-sg";
driver.get(baseurl);
driver.findElement(By.linkText("Make xinmsn my homepage")).click();
            //selenium.openWindow("","modal");
            //selenium.waitForPopUp("modal","15000");
             //selenium.selectWindow("name=modal");
            for(String handle:driver.getWindowHandles()){
                    driver.switchTo().window(handle);
            }
}
}
MillionRoses 引用 删除 dian106106   /   2012-05-15 16:03:24
Robot robot;
        try
        {
            robot = new Robot();
            robot.keyPress(KeyEvent.VK_UP);
            robot.delay(1000);
            robot.keyPress(KeyEvent.VK_UP);
            robot.delay(1000);
            robot.keyPress(KeyEvent.VK_TAB);
            robot.delay(1000);  
            robot.keyRelease(KeyEvent.VK_TAB);
            robot.delay(1000);
            robot.keyPress(KeyEvent.VK_ENTER);
        } catch (AWTException e)
        {
            e.printStackTrace();
        }
 

评分:0

我来说两句

日历

« 2024-05-14  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 74682
  • 日志数: 80
  • 建立时间: 2012-04-12
  • 更新时间: 2013-05-21

RSS订阅

Open Toolbar