简体   繁体   English

硒代码打开并创建多个驱动程序和选项

[英]selenium code to open and make multiple drivers and options

I need to make multiple webdrivers and open it at once 我需要制作多个网络驱动程序并立即将其打开

I ve tried code bellow.. 我已经尝试过以下代码了..

public static WebDriver[] driver = new ChromeDriver[99];

public static ChromeOptions[] optionss = new ChromeOptions[99];

public static String[] opt = new String[99];

for(int i=0;i<=99;i++) {
            opt[i] ="user-data-dir=C:\\Users\\dam\\AppData\\Local\\Google\\Chrome\\User Data\\Profile "+i;
            optionss[i].addArguments(opt[i]);
            driver[i] = new ChromeDriver(optionss[i]);
            driver[i].get("https://google.com");
        }

I need to make 100 drivers that open at once, and each driver opens exact chrome profile 我需要使100个驱动程序一次打开,并且每个驱动程序都打开精确的chrome配置文件

This Works: 这有效:

    System.setProperty("webdriver.chrome.driver", System.clearProperty("user.dir")+"\\resources\\chromedriver.exe");
    WebDriver[] drivers = new ChromeDriver[5];// change array size to meet your demand


    for(int i=0;i<5;i++) {// change loop iterations to match array size
        String opt ="user-data-dir=C:\\Users\\dam\\AppData\\Local\\Google\\Chrome\\User Data\\Profile"+i;
        ChromeOptions option = new ChromeOptions();
        option.addArguments(opt);
        ChromeDriver driver = new ChromeDriver(option);
        drivers[i] = driver;
        drivers[i].get("https://google.com");
    }

However, there is a delay between each browser opening as the for loop executes. 但是,在执行for循环时,每个浏览器之间都存在延迟。

Hope this helps :) goodluck 希望这有帮助,祝你好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM