我能夠做到如下:
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
和嘗試。
非常感謝你的幫助完整:) –