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

    }

  • 相关阅读:
    Android使用LocalSocket抓取数据
    求一个数组的最长递减子序列 比如{9,4,3,2,5,4,3,2}的最长递减子序列为{9,5,4,3,2}
    链表A和B的有序合并,合并过程不产生新的节点,合并后B消失
    Android中intent如何传递自定义数据类型
    字符串的排列组合问题
    android.net.LocalSocket
    [转]OWC生成柱图,线图,饼图
    利用C#对远程服务进行操作
    域备份&域还原
    ActiveReports for .NET 简单使用
  • 原文地址:https://www.cnblogs.com/backpacker/p/2788909.html
Copyright © 2011-2022 走看看