zoukankan      html  css  js  c++  java
  • WebDriver 中使用 Javascript

    Use Javascript in WebDriver

    package com.example.tests;

    import java.io.File;
    import java.util.regex.Pattern;
    import java.util.concurrent.TimeUnit;
    import org.junit.*;
    import static org.junit.Assert.*;
    import static org.hamcrest.CoreMatchers.*;
    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.support.ui.Select;

    public class BenbriaSele01 {
        private WebDriver driver;
        private String baseUrl;
        private StringBuffer verificationErrors = new StringBuffer();
        @Before
        public void setUp() throws Exception {
            
            
            //Use IE driver
            File file = new File("E:/SW/Selenium/IEDriverServer32.exe");
            System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
            DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
            capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            capabilities.setCapability("ignoreProtectedModeSettings",true);
            driver = new InternetExplorerDriver(capabilities);
            

            
    //        //Use Firefox
    //        driver = new FirefoxDriver();

            
            baseUrl = "http://10.1.3.12/";
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            
        }

        @Test
        public void testBenbriaSele01() throws Exception {
    //        driver.get(baseUrl + "/blazecast/login.jsf");
            driver.get(baseUrl);
            driver.findElement(By.id("username")).sendKeys("admin");
            driver.findElement(By.id("password")).sendKeys("admin");
    //        driver.findElement(By.id("login_submit")).click();
            JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("document.getElementById(\"login_submit\").click()",true);
        }

        @After
        public void tearDown() throws Exception {
    //        driver.quit();
    //        String verificationErrorString = verificationErrors.toString();
    //        if (!"".equals(verificationErrorString)) {
    //            fail(verificationErrorString);
    //        }
            System.out.println("tearDown!");
        }

    }

  • 相关阅读:
    Linux添加硬盘并分区格式化
    Struts2/XWork 安全漏洞及解决办法
    Java中ArrayList和 LinkedList区别
    java位操作
    Spring Cloud Config 分布式配置中心【Finchley 版】
    实现win2003下mysql数据库每天自动备份
    模仿IE自动完成功能,非常完美(转)
    高级自定义查询、分页、多表联合存储过程(转)
    文本框位置
    英文论坛常用
  • 原文地址:https://www.cnblogs.com/backpacker/p/2788909.html
Copyright © 2011-2022 走看看