• selenium 等待页面加载完成


    一、隐形加载等待:

    file:///C:/Users/leixiaoj/Desktop/test.html 该页面负责创建一个div 
    <html>
    <head>
        <title>Set Timeout</title>
        <style>
            .red_box {background-color: red; width = 20%; height:100px; border: none;}
        </style>
        <script>
            function show_div(){
                setTimeout("create_div()", 5000);
            }
            function create_div(){
                d = document.createElement('div');
                d.className = "red_box";
                document.body.appendChild(d);
            }
        </script>
    </head>
    <body>
        <button id = "b" onclick = "show_div()">click</button>
    </body>
    </html>
    等候10s后再修改div
    //隐式等待
    public
    static void main(String[] args) throws InterruptedException { WebDriver dr = new FirefoxDriver(); //设置10 秒 dr.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); String url = "file:///C:/Users/leixiaojiang/Desktop/test.html"; dr.get(url); dr.findElement(By.id("b")).click(); WebElement element =dr.findElement(By.cssSelector(".red_box")); ((JavascriptExecutor)dr).executeScript("arguments[0].style.border ="5px solid yellow"",element); }
           //显式等待
           WebDriver dr = new FirefoxDriver();
            
            String url = "file:///C:/Users/leixiaojiang/Desktop/test.html";
            dr.get(url);
            WebDriverWait wait = new WebDriverWait(dr,10);
            wait.until(new ExpectedCondition<WebElement>(){
            @Override
            public WebElement apply(WebDriver d) {return d.findElement(By.id("b"));}
            }).click();
            //上面的点击操作5s后才有red_box这个类出现
            WebDriverWait wait1 = new WebDriverWait(dr,10);
            WebElement element =dr.findElement(By.cssSelector(".red_box"));
            ((JavascriptExecutor)dr).executeScript("arguments[0].style.border ="5px solid yellow"",element);

  • 相关阅读:
    join()方法作用
    多线程的运行状态
    守护线程和非守护线程
    多线程快速入门
    Spring Boot2.0之注解方式启动Springmvc
    Spring Boot2.0之 原理—创建内置Tomcat容器
    Spring Boot2.0之纯手写框架
    Sprin Boot2.0之整合Mybatis整合分页插件
    linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制)
    PHP编程效率的20个要点
  • 原文地址:https://www.cnblogs.com/Lxiaojiang/p/6248496.html
Copyright © 2020-2023  润新知