我能够做到以下几点:
Actions act = new Actions(driver);//driver variable is chrome web driver ref
WebElement selectInput=driver.findElement(By.className("Select-input"));//Thread.sleep(5000);
act.click(selectInput).build().perform();//Thread.sleep(5000);
//list of all option
List<WebElement> selectValues=driver.findElements(By.className("Select-option"));//Thread.sleep(5000);
//first option:
WebElement firstWebElement=selectValues.get(0);//Thread.sleep(5000);
act.click(firstWebElement).build().perform();//Thread.sleep(5000);
我已经评论了线程的睡眠,因为我在本地运行,有时需要时间从远程机器上的 UI 中获取元素,所以在这种情况下取消注释Thread.sleep
并尝试。