• 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!");
        }

    }

  • 相关阅读:
    SQL(4)— Date、order by
    步入三十(二)
    【js】特殊字符转义
    【ionic】项目中$ionicModal简单用法
    【ionic】常见问题处理
    【js】视频截图
    实现笔记本拔除电源后修改屏幕缩放比例
    激活 公众号java
    【Golang】基于beego/orm实现相同表结构不同表名的分表方法实现
    .Net Cors 跨域配置域名通配符
  • 原文地址:https://www.cnblogs.com/backpacker/p/2788909.html
Copyright © 2020-2023  润新知