[英]selenium code to open and make multiple drivers and options
我需要制作多個網絡驅動程序並立即將其打開
我已經嘗試過以下代碼了..
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");
}
我需要使100個驅動程序一次打開,並且每個驅動程序都打開精確的chrome配置文件
這有效:
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");
}
但是,在執行for循環時,每個瀏覽器之間都存在延遲。
希望這有幫助,祝你好運
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.