zoukankan      html  css  js  c++  java
  • chromedriver的使用

    1.调用chrome driver

    System.setProperty("webdriver.chrome.driver", "C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe");
    

    2.创建chromeOption对象

    ChromeOptions chromeOptions = new ChromeOptions();

    3.属性设置

    3.1无图设置:

    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("profile.managed_default_content_settings.images", 2);
    chromeOptions.setExperimentalOption("prefs",prefs);

    3.2设置免检测(开发者模式)

    List excludeSwitches=new ArrayList<String>();
    excludeSwitches.add("enable-automation");
    chromeOptions.setExperimentalOption("excludeSwitches",excludeSwitches);

    3.3设置代理ip

    String ip = "122.236.112.128:4267";
    chromeOptions.addArguments("--proxy-server=http://" + ip);

    3.4设置浏览器大小

    WebDriver driver = new ChromeDriver(chromeOptions);
    //调整浏览器大小
    driver.manage().window().setSize(new Dimension(1300, 800));
    ((ChromeDriver) driver).get(url);

    3.5设置Cookie

    Cookie cookie = new Cookie("name","value");
    driver.manage().addCookie(cookie);

    3.6设置无头

    chromeOptions.addArguments("-headless");

    本文来源于 ushowtime https://www.ushowtime.cn

  • 相关阅读:
    java I/O框架 (三)基本流
    java I/O框架 (二)文件操作(File)
    java I/O框架 (一)总览
    8.内部类
    7.权限
    6.继承
    5.代码块
    4.面向对象
    3控制语句
    PHP ksort() 函数
  • 原文地址:https://www.cnblogs.com/ushowtime/p/11619333.html
Copyright © 2011-2022 走看看