zoukankan      html  css  js  c++  java
  • 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");
            }
        }
  • 相关阅读:
    04.VUE学习之v-text v-html
    03.VUE学习之动态绑定值
    2019年Vue学习路线图
    02.VUE学习二之数据绑定
    01.VUE学习一
    一张图解析FastAdmin中的表格列表的功能
    python 正则表达式与JSON字符串
    jQuery的select2下拉框的搜索功能(使用select2插件,方便简单)
    笔记1 python入门学习笔记
    MySQL----Navicat使用
  • 原文地址:https://www.cnblogs.com/RENQIWEI1995/p/7793676.html
Copyright © 2011-2022 走看看