本文整理汇总了Java中org.openqa.selenium.support.ui.Wait类的典型用法代码示例。如果您正苦于以下问题:Java Wait类的具体用法?Java Wait怎么用?Java Wait使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Wait类属于org.openqa.selenium.support.ui包,在下文中一共展示了Wait类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForElementToAppear
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
* Wait for element to appear.
*
* @param driver the driver
* @param element the element
* @param logger the logger
*/
public static boolean waitForElementToAppear(WebDriver driver, WebElement element, ExtentTest logger) {
boolean webElementPresence = false;
try {
Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(2, TimeUnit.SECONDS)
.withTimeout(60, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
fluentWait.until(ExpectedConditions.visibilityOf(element));
if (element.isDisplayed()) {
webElementPresence= true;
}
} catch (TimeoutException toe) {
logger.log(LogStatus.ERROR, "Timeout waiting for webelement to be present<br></br>" + toe.getStackTrace());
} catch (Exception e) {
logger.log(LogStatus.ERROR, "Exception occured<br></br>" + e.getStackTrace());
}
return webElementPresence;
}
示例2: progress
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public void progress() throws Throwable {
driver = new JavaDriver();
final WebElement progressbar = driver.findElement(By.cssSelector("progress-bar"));
AssertJUnit.assertNotNull("could not find progress-bar", progressbar);
AssertJUnit.assertEquals("0", progressbar.getAttribute("value"));
driver.findElement(By.cssSelector("button")).click();
Wait<WebDriver> wait = new WebDriverWait(driver, 30);
// Wait for a process to complete
wait.until(new ExpectedCondition<Boolean>() {
@Override public Boolean apply(WebDriver webDriver) {
return progressbar.getAttribute("value").equals("100");
}
});
AssertJUnit.assertEquals("100", progressbar.getAttribute("value"));
AssertJUnit.assertTrue(driver.findElement(By.cssSelector("text-area")).getText().contains("Done!"));
}
示例3: switchToWindowByTitle
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private void switchToWindowByTitle(
final String windowTitle,
long timeoutInSeconds ) {
ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
public Boolean apply(
WebDriver driver ) {
return switchToWindowByTitle(windowTitle);
}
};
Wait<WebDriver> wait = new WebDriverWait(webDriver, timeoutInSeconds);
try {
wait.until(expectation);
} catch (Exception e) {
throw new SeleniumOperationException("Timeout waiting for Window with title '" + windowTitle
+ "' to appear.", e);
}
}
示例4: waitOverridingImplicitWait
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
* If there is an implicit wait set, then you might need to wait for a shorter period. This
* method makes it possible with setting the implicit wait temporarily to 0.
*
* @param webDriver webdriver to be used
* @param seconds timeout in seconds
* @return a {@link Wait} instance, which set the implicit wait temporarily to 0.
*/
public Wait<WebDriver> waitOverridingImplicitWait(WebDriver webDriver, int seconds) {
//API comes from selenium -> cannot migrate guava to java 8
//noinspection Guava
return new Wait<WebDriver>() {
@Override
public <T> T until(Function<? super WebDriver, T> function) {
Timeouts timeouts = webDriver.manage().timeouts();
try {
timeouts.implicitlyWait(0, TimeUnit.SECONDS);
return new WebDriverWait(webDriver, seconds, CONDITION_POLL_INTERVAL).until(function);
} finally {
timeouts.implicitlyWait(implicitWait.getNano(), TimeUnit.NANOSECONDS);
}
}
};
}
示例5: waitForPageLoad
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public static void waitForPageLoad(WebDriver driver) {
Wait<WebDriver> wait = new WebDriverWait(driver, 30);
wait.until(new Function<WebDriver, Boolean>() {
/* (non-Javadoc)
* @see java.util.function.Function#apply(java.lang.Object)
*/
public Boolean apply(WebDriver driver_) {
System.out.println("Current Window State : "
+ String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState")));
return String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
.equals("complete");
}
});
}
示例6: marcarDiaCalendari
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private void marcarDiaCalendari(String idElem, boolean festiu) {
String xPathFinal = "";
if (festiu) {
xPathFinal = "//*[@id='"+idElem+"'][contains(@class, 'festiu')]";
}else{
xPathFinal = "//*[@id='"+idElem+"'][not[contains(@class, 'festiu')]]";
}
//Clicam l´element y esperam un max de 10s si la pagina es recarrega amb l´element indicat marcat com a festiu o no (segons el booleà passat)
driver.findElement(By.id(idElem)).click();
//Esperam fins a trobar la cel.la corresponent a dia 1 de gener de l´any escollit (maxim 10s.)
Wait<WebDriver> wait = new WebDriverWait(driver, 10);
try {
wait.until(visibilityOfElementLocated(By.xpath(xPathFinal)));
}catch (Exception ex) {}
}
示例7: showHeaderMenuIfCollapsed
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private void showHeaderMenuIfCollapsed() {
Wait<WebDriver> wait = BaseUITest.newDefaultWait();
// If browser is opened with width of 960 pixels or less
// then the Header Menu is not displayed and a 'Hamburger' button is displayed instead.
// This button needs to be clicked to display the Header Menu.
if (!headerMenu.isDisplayed()) {
if (!hamburgerButton.isDisplayed()) {
// Sometimes the Hamburger button is not initially displayed
// so click the Header element to display the button
this.click();
}
hamburgerButton.click();
// Ensure the Header Menu is displayed before attempting to click a link
wait.until(ExpectedConditions.visibilityOf(headerMenu));
}
}
示例8: waitForPageLoaded
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
* Wait For the Page to Load in the Browser
*
* @param driver
*/
public synchronized void waitForPageLoaded() {
ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) DriverManager.getDriver()).executeScript(
"return document.readyState").equals("complete");
}
};
Wait<WebDriver> wait = new WebDriverWait(DriverManager.getDriver(), 30);
try {
wait.until(expectation);
} catch (Throwable error) {
new SelTestException(
"Timeout waiting for Page Load Request to complete.");
}
}
示例9: doWaitElement
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private WebElement doWaitElement(final WebLocator el, final long millis) {
Wait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(millis, TimeUnit.MILLISECONDS)
.pollingEvery(1, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(ElementNotVisibleException.class)
.ignoring(WebDriverException.class);
try {
if (el.getPathBuilder().isVisibility()) {
el.currentElement = wait.until(ExpectedConditions.visibilityOfElementLocated(el.getSelector()));
} else {
el.currentElement = wait.until(d -> d.findElement(el.getSelector()));
}
} catch (TimeoutException e) {
el.currentElement = null;
}
return el.currentElement;
}
示例10: isElementNotPresentAfterWait
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
* is Element Not Present After Wait
*
* @param timeout in seconds
* @return boolean - false if element still present after wait - otherwise true if it disappear
*/
public boolean isElementNotPresentAfterWait(final long timeout) {
final ExtendedWebElement element = this;
LOGGER.info(String.format("Check element %s not presence after wait.", element.getName()));
Wait<WebDriver> wait =
new FluentWait<WebDriver>(getDriver()).withTimeout(timeout, TimeUnit.SECONDS).pollingEvery(1,
TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
try {
return wait.until(driver -> {
boolean result = driver.findElements(element.getBy()).isEmpty();
if (!result) {
LOGGER.info(String.format("Element '%s' is still present. Wait until it disappear.", element
.getNameWithLocator()));
}
return result;
});
} catch (Exception e) {
LOGGER.error("Error happened: " + e.getMessage(), e.getCause());
LOGGER.warn("Return standard element not presence method");
return !element.isElementPresent();
}
}
示例11: waitForElementToDisappear
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
* Wait for element to disappear.
*
* @param driver the driver
* @param element the element
* @param logger the logger
* @return true, if successful
*/
public static boolean waitForElementToDisappear(WebDriver driver, WebElement element, ExtentTest logger) {
try {
Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS)
.pollingEvery(2, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
fluentWait.until(ExpectedConditions.invisibilityOf(element));
return true;
} catch (Exception e) {
logger.log(LogStatus.ERROR,
"Error occured while waiting for element to disappear</br>" + e.getStackTrace());
return false;
}
}
示例12: b1_canviar_any
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
@Test
public void b1_canviar_any() {
carregarUrlConfiguracio();
accedirConfiguracioFestius();
screenshotHelper.saveScreenshot("configuracio/festius/b1_1_llista_festius_any_actual.png");
//Seleccionar any anterior
String anyAnterior = Integer.toString(dataAvull.get(Calendar.YEAR)-1);
for (WebElement option : driver.findElement(By.xpath("//*[@id='content']/h3/form/select")).findElements(By.tagName("option"))) {
if (anyAnterior.equals(option.getAttribute("value"))) {
option.click();
break;
}
}
//Funcio que marca un dia del calendari (donada la id) y espera un maxim de 7s fins que es carregui el nou calendari via ajax.
//Esperam fins a trobar la cel.la corresponent a dia 1 de gener de l´any escollit (maxim 10s.)
Wait<WebDriver> wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(visibilityOfElementLocated(By.id("dia_01/01/"+anyAnterior)));
if (element==null) {
fail("La pagina del calendari corresponent a l'id dia_01/01/"+anyAnterior+" ha tardat massa a carregar.");
}else{
screenshotHelper.saveScreenshot("configuracio/festius/b1_2_llista_festius_any_anterior.png");
}
}
示例13: waitForElementPresent
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public static void waitForElementPresent(WebDriver driver, WebElement element){
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(60, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.visibilityOf(element));
}
示例14: openPullRequestOnGitHub
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public void openPullRequestOnGitHub() {
Wait<WebDriver> wait =
new FluentWait(seleniumWebDriver)
.withTimeout(ATTACHING_ELEM_TO_DOM_SEC, SECONDS)
.pollingEvery(500, MILLISECONDS)
.ignoring(WebDriverException.class);
wait.until(visibilityOfElementLocated(By.xpath(PullRequestLocators.OPEN_GITHUB_BTN))).click();
}
示例15: openServersTabFromContextMenu
import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public void openServersTabFromContextMenu(String machineName) {
Wait<WebDriver> wait =
new FluentWait<WebDriver>(seleniumWebDriver)
.withTimeout(ELEMENT_TIMEOUT_SEC, SECONDS)
.pollingEvery(500, MILLISECONDS)
.ignoring(WebDriverException.class);
WebElement machine =
wait.until(visibilityOfElementLocated(By.xpath(format(MACHINE_NAME, machineName))));
wait.until(visibilityOf(machine)).click();
actionsFactory.createAction(seleniumWebDriver).moveToElement(machine).contextClick().perform();
redrawDriverWait.until(visibilityOf(serversMenuItem)).click();
}