• java工作复习——4大时间等待——隐式等待等待(driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);)


    package jkcs;
    
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.NoSuchElementException;
    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    public class jdcs 
    {
        
        public static void main(String[] args) throws InterruptedException 
        {
             System.setProperty("webdriver.chrome.bin","‪C:\Program Files (x86)\Mozilla Firefox\firefox.exe");    //设置安装路径,防止系统找不到
             
             WebDriver driver = new FirefoxDriver();
             driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
             driver.get("http://www.baidu.com");
             driver.manage().window().maximize();
    
             try {
                 SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss-SSS");
                 String time = format.format(Calendar.getInstance().getTime());
                 System.out.println("开始的时间: " + time);
    
                 driver.findElement(By.id("kw22")).sendKeys("selenium");
    
             } catch (NoSuchElementException e) {
                 System.out.println("没有找到元素");
                 e.printStackTrace();
             } finally {
                 SimpleDateFormat format2 = new SimpleDateFormat("HH-mm-ss-SSS");
                 String time2 = format2.format(Calendar.getInstance().getTime());
                 System.out.println("结束的时间: " + time2);
                 driver.quit();
             }
        }
    }

    执行结果:

  • 相关阅读:
    梯度下降(Gradient Descent)
    Positioning-Based Photo Retrieval
    NTU Long-Term Positioning Dataset
    Pycharm导入tabula模块包
    MySQL学习笔记20
    MySQL学习笔记17-19
    Android studio 报错AAPT2 error
    MySQL学习笔记13-16
    MySQL学习笔记 8-12
    机器学习十大算法
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12751311.html
Copyright © 2020-2023  润新知