• 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浏览器如何调用,待整理好补充。

  • 相关阅读:
    c# PrintDocument 设置自定义纸张大小的示例
    C#获取本地打印机列表,并将指定打印机设置为默认打印机
    水晶报表自定义纸张大小打印 (Crystal Report Print with custom paper size)
    c#打印机设置,取得打印机列表及相应打印机的所有纸张格式
    在C#中设置打印机纸张大小
    打印grid
    获取List集合中最大值的方法
    mysql使用索引优化查询效率
    mysql数据库中标的key的含义
    mysql数据库添加索引优化查询效率
  • 原文地址:https://www.cnblogs.com/xmmc/p/7491974.html
Copyright © 2020-2023  润新知