Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用字符串数组在下拉列表中存储值?调用selenium web驱动程序_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 如何使用字符串数组在下拉列表中存储值?调用selenium web驱动程序

Java 如何使用字符串数组在下拉列表中存储值?调用selenium web驱动程序,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在创建脚本,但并没有得到完美的调用。请帮助我如何在数组中创建脚本下拉值存储。我无法调用selenium web驱动器 下拉菜单scrrenshot: 下拉菜单列表: 谢谢WebElement facultyId=driver.findElement(By.id(“faculty_id”); facultyId.click();//使选项显示 线程。睡眠(500);//如果不使用隐式等待 列表值=新的ArrayList(); 列表文本=新的ArrayList(); 列表选项=facultyId

我正在创建脚本,但并没有得到完美的调用。请帮助我如何在数组中创建脚本下拉值存储。我无法调用selenium web驱动器

下拉菜单scrrenshot: 下拉菜单列表:

谢谢

WebElement facultyId=driver.findElement(By.id(“faculty_id”);
facultyId.click();//使选项显示
线程。睡眠(500);//如果不使用隐式等待
列表值=新的ArrayList();
列表文本=新的ArrayList();
列表选项=facultyId.findElements(按.tagName(“选项”));
用于(WebElement选项:选项){
add(option.getAttribute(“value”);
text.add(option.getText());
}
字符串[]collectedValues=(字符串[])值。toArray();
String[]CollectedText=(String[])text.toArray();

检查下面的答案我用过这个脚本

// options to appear
driver.findElement(By.xpath("//*[@id=\"s2id_autogen3\"]")).click(); // options to appear
       Thread.sleep(6000);
       driver.findElement(By.xpath("//*[@id=\"s2id_autogen3\"]")).sendKeys("Office Department"); //pass the sendkeys
       Thread.sleep(6000);
       
       //Use the Using explicit wait
       WebDriverWait Faculties = new WebDriverWait(driver, 120);
       WebElement Departments =Faculties.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("*//Put the xpath for finding keyword"))); //Put the xpath for finding keyword  
       Departments.click(); //Click on finding keyword

我正在尝试使用上面提到的脚本,但它不是下拉值clickable和获取值。我已经编辑了我的答案。请始终发布您的代码,包括控制台输出。仍然不工作。Html代码=脚本代码=控制台输出=
// options to appear
driver.findElement(By.xpath("//*[@id=\"s2id_autogen3\"]")).click(); // options to appear
       Thread.sleep(6000);
       driver.findElement(By.xpath("//*[@id=\"s2id_autogen3\"]")).sendKeys("Office Department"); //pass the sendkeys
       Thread.sleep(6000);
       
       //Use the Using explicit wait
       WebDriverWait Faculties = new WebDriverWait(driver, 120);
       WebElement Departments =Faculties.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("*//Put the xpath for finding keyword"))); //Put the xpath for finding keyword  
       Departments.click(); //Click on finding keyword