等待<webdriver> wait = new FluentWait <webdriver>(驱动程序)无效

时间:2018-04-13 13:56:19

标签: java selenium-webdriver selenium-chromedriver

public class testTime extends runAutomation{

    static WebElement element = null;
    static String driverPath = "<Path>//chromedriver_win32//chromedriver.exe";
    static String username = null;
    static String password = null;

    public static void main(String[] args) throws InterruptedException{
        System.setProperty("webdriver.chrome.driver", driverPath);
        ChromeOptions options = new ChromeOptions(); 
        options.addArguments("disable-extensions");
        driver = new ChromeDriver(options);
        driver.get("URL");
        driver.manage().window().maximize();
        SixLabels page = new SixLabels();
        page.doLogin();
    }
} 

public class SixLabels extends testTime{
    static WebDriverWait wait = new WebDriverWait(driver, 60);

    public static WebElement userName(WebDriver driver){
        element = driver.findElement(By.id("UserName"));
        return element ;
    }

    public static WebElement password(WebDriver driver){
        element = driver.findElement(By.id("Password"));
        return element ;
    }

    private void adminMenuClick(WebDriver driver) throws InterruptedException {
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)     
            .pollingEvery(30, TimeUnit.SECONDS)       
            .ignoring(NoSuchElementException.class);         
        WebElement waitingElement = wait.until(new Function<WebDriver, 
        WebElement>() {
            public WebElement apply(WebDriver driver) {
            return driver.findElement(By.linkText("ADMINISTRATIVE MODULE"));
            }
        });
        waitingElement.click();
}

    public void doLogin() throws InterruptedException{
        userName(driver);
        element.sendKeys("uname");
        Password(driver);
        element.sendKeys("@password");
        LoginButton(driver);
        element.click();
        adminMenuClick(driver);
    }
}

许多人建议放置Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)等待该元素可用于点击。但是当我尝试使用它时,这不起作用。我必须把Thread.sleep(4000);明确地在每次点击之间。请有人给我正确的解决方案

0 个答案:

没有答案