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);明确地在每次点击之间。请有人给我正确的解决方案