• selenium模拟登录_百度指数


    java main
        WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://index.baidu.com"); WebElement baiduLogin = driver.findElement(By.linkText("登录")); baiduLogin.click(); WebElement userNameBox = driver.findElement(By.id("TANGRAM_12__userName")); userNameBox.sendKeys("1234567890"); WebElement passwordBox = driver.findElement(By.id("TANGRAM_12__password")); passwordBox.sendKeys("asd"); WebElement loginButton = driver.findElement(By.id("TANGRAM_12__submit")); loginButton.submit(); Thread.sleep(3000); WebElement searchBox = driver.findElement(By.id("schword")); searchBox.sendKeys("汽车"); searchBox.submit(); Thread.sleep(2000); snapshot((TakesScreenshot)driver,"汽车.png");

    //主方法

    public static void snapshot(TakesScreenshot drivername, String filename){
            // this method will take screen shot ,require two parameters ,one is driver name, another is file name
    
            File scrFile = drivername.getScreenshotAs(OutputType.FILE);
            // Now you can do whatever you need to do with it, for example copy somewhere
            try {
                System.out.println("save snapshot path is:"+filename);
                FileUtils.copyFile(scrFile, new File(filename));
            } catch (IOException e) {
                System.out.println("Can't save screenshot");
                e.printStackTrace();
            } 
            finally{
                System.out.println("screen shot finished");
            }
        }
  • 相关阅读:
    c# 序列化和反序列化
    dataGridView通过checkbox选择数据
    获取文件后缀名(迟点写入自己的类库里面去) .NET
    刚在《微软中国msdn围脖》看到面试题
    jquery 遍历下拉框
    html代码转换成为纯文本
    获取ListBox中多选值
    递归算法运用到实际项目,可行吗?
    ExtJs学习笔记1
    JS 可变参数 arguments
  • 原文地址:https://www.cnblogs.com/RENQIWEI1995/p/7793676.html
Copyright © 2020-2023  润新知