如何为这个离子角度下拉代码编写脚本以在 selenium java webdriver 中进行测试

问题描述 投票:0回答:1

如何在java中为这个离子角度下拉代码编写selenium webdriver脚本 我想单击下拉列表并在该下拉列表中选择一个元素。授予的角色是“MANAGER”、“TRAINEE”

这是我的角度代码: {{授予角色}}

java angular selenium-webdriver ionic-framework
1个回答
0
投票
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();
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.