📜  如何在 java selenium 中迭代列表 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:07.946000             🧑  作者: Mango

代码示例2
public Boolean selectByText( String text ) {
    WebElement dropDown = driver.findElement( By.xpath( ".//dropdown/path" ) );
    dropDown.click();
    List allOptions = dropDown.findElements(By.xpath(".//option"));
    for ( WebElement we: allOptions) { 
        dropDown.sendKeys( Keys.DOWN ); //simulate visual movement
        sleep(250);       
        if ( we.getText().contains( text ) ) select.selectByVisibleText("Value1");
    }
}