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");
            }
        }
  • 相关阅读:
    一次使用布隆过滤器的经历
    从C#到Java(effective-java阅读笔记)
    从C#到Java(泛型)
    Dubbo学习-第一章
    从C#到Java(Spring拦截器HandlerInterceptor )
    从C#到Java(Aspect)
    从C#到Java(SpringBoot入门)
    从C#到Java(lambda比较)
    Redis添加List
    Three.js学习(相机,场景,渲染,形状)
  • 原文地址:https://www.cnblogs.com/RENQIWEI1995/p/7793676.html
Copyright © 2011-2022 走看看