如何在java中为这个离子角度下拉代码编写selenium webdriver脚本 我想单击下拉列表并在该下拉列表中选择一个元素。授予的角色是“MANAGER”、“TRAINEE”
这是我的角度代码:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ExplicitWaitDropdownExample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
try {
driver.get("your-angular-app-url");
WebElement dropdown = driver.findElement(By.name("userRole"));
dropdown.click();
// Use explicit wait for the dropdown to be clickable
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement option = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//ion-select-option[text()='MANAGER']")));
// Click the desired option
option.click();
} finally {
driver.quit();
}
}
}