zoukankan      html  css  js  c++  java
  • Selenium_IE11_FireFox调用实例

    1)使用Selenium调用IE11

        1、前期准备参考博客:http://blog.csdn.net/jichuang123/article/details/53008581

             备注:按照上述博客操作完成后一定要关机再开机,配置的注册表信息才能生效,重启电脑启不到对应的效果。

        2、编写Selenium代码

    package com.testng.webdriver;
    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeMethod;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.testng.annotations.AfterMethod;
    
    public class TestIe {
        public WebDriver driver;
        String baseUrl = "http://www.sogou.com/";
          @Test
          public void testSearch() {
              driver.get(baseUrl);
              driver.findElement(By.id("query")).sendKeys("光荣之路自动化测试");
              driver.findElement(By.id("stb")).click();
          }
          @BeforeMethod
          public void beforeMethod() {
              //设置IE浏览器默认存储位置 
              driver = new InternetExplorerDriver();
              System.setProperty("webdriver.ie.driver", "C:\Program Files (x86)\Internet Explorer\IEDriverServer.exe");
              //设置浏览器为全屏模式
              driver.manage().window().maximize();
          }
    
          @AfterMethod
          public void afterMethod() {
              //退出浏览器
              driver.quit();
          }
    }

    2)使用Selenium调用FireFox

         因为Firefox自身已经集成了插件,所以不需要单独下载插件,直接使用如下代码就OK;

      

    package com.testng.webdriver;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;
    
    public class TestFireFox {
        public WebDriver driver;
        String baseUrl = "http://www.sogou.com/";
          @Test
          public void testSearch() {
              driver.get(baseUrl);
              driver.findElement(By.id("query")).sendKeys("光荣之路自动化测试");
              driver.findElement(By.id("stb")).click();
          }
          @BeforeMethod
          public void beforeMethod() {
              //创建火狐 
              driver = new FirefoxDriver();
              //设置火狐浏览器默认存储位置 
              System.setProperty("webdriver.firefox.bin", "C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
              //设置浏览器为全屏模式
              driver.manage().window().maximize();
          }
    
          @AfterMethod
          public void afterMethod() {
              //退出浏览器
              driver.quit();
          }
    }

     Chrome浏览器如何调用,待整理好补充。

  • 相关阅读:
    巧用table的rules属性设置表格的边框掩饰。。。
    JS日期和时间
    onchange事件验证文本框格式,不正确光标返回原文本框,这个js怎么写?
    简易万用表
    在单片机中的空函数
    地感线圈的讲究
    全桥片
    这个当单片机程序怎么会不停的通过串口发数据,设置波特率为9600,但是串口软件接受数据不对(初学者,请高手指教)
    今天开博
    关于二极管
  • 原文地址:https://www.cnblogs.com/xmmc/p/7491974.html
Copyright © 2011-2022 走看看