selenium 顯示等待例項 org.openqa.selenium.support.ui.FluentWait
Example 1
Project: easycukes File: SeleniumHelper.java View source code | 7 votes |
/** * @param by * @return */ public static void waitUntilValueIsSelected(@NonNull final WebDriver driver, @NonNull final By by, @NonNull final String value) { final FluentWait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS) .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver webDriver) { try { final WebElement webElement = webDriver.findElement(by); new Select(webElement).selectByValue(value); return webElement.getAttribute("value").equals(value); } catch (final StaleElementReferenceException e) { return false; } } }); }
Example 2
Project: POM_HYBRID_FRAMEOWRK File: WebUtilities.java View source code | 6 votes |
/** * 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; }
Example 3
Project: WebAutomation_AllureParallel File: FluentWaiting.java View source code | 6 votes |
public static void waitUntillElementToBeClickable(int TotalTimeInSeconds, int PollingTimeInMilliseconds, WebElement Element) { FluentWait<WebDriver> ClickableWait = new FluentWait<WebDriver>(getWebDriver()) .withTimeout(TotalTimeInSeconds, TimeUnit.SECONDS) .pollingEvery(PollingTimeInMilliseconds, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); ClickableWait.until(ExpectedConditions.elementToBeClickable(Element)); }
Example 4
Project: Quantum File: AppiumUtils.java View source code | 6 votes |
private static MobileElement fluentWait(AppiumDriver driver, By xpath) {
MobileElement waitElement = null;
FluentWait<RemoteWebDriver> fwait = new FluentWait<RemoteWebDriver>(driver).withTimeout(15, TimeUnit.SECONDS)
.pollingEvery(500, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);
try {
waitElement = (MobileElement) fwait.until(new Function<RemoteWebDriver, WebElement>() {
public WebElement apply(RemoteWebDriver driver) {
return driver.findElement(xpath);
}
});
} catch (Exception e) {
}
return waitElement;
}
Example 5
Project: menggeqa File: AppiumElementLocator.java View source code | 6 votes |
private List<WebElement> waitFor() {
// When we use complex By strategies (like ChainedBy or ByAll)
// there are some problems (StaleElementReferenceException, implicitly
// wait time out
// for each chain By section, etc)
try {
changeImplicitlyWaitTimeOut(0, TimeUnit.SECONDS);
FluentWait<By> wait = new FluentWait<>(by);
wait.withTimeout(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
return wait.until(waitingFunction);
} catch (TimeoutException e) {
return new ArrayList<>();
} finally {
changeImplicitlyWaitTimeOut(timeOutDuration.getTime(), timeOutDuration.getTimeUnit());
}
}
Example 6
Project: che File: TestWebElementRenderChecker.java View source code | 6 votes |
private void waitElementIsStatic(FluentWait<WebDriver> webDriverWait, WebElement webElement) {
AtomicInteger sizeHashCode = new AtomicInteger();
webDriverWait.until(
(ExpectedCondition<Boolean>)
driver -> {
Dimension newDimension = waitAndGetWebElement(webElement).getSize();
if (dimensionsAreEquivalent(sizeHashCode, newDimension)) {
return true;
} else {
sizeHashCode.set(getSizeHashCode(newDimension));
return false;
}
});
}
Example 7
Project: NYU-Bobst-Library-Reservation-Automator-Java File: RunAutomator.java View source code | 6 votes |
/**
* The wrapper for the actual run automator
* @param browser The current browser for this run
* @param user The current user for this run
* @param offset The current amount of offsets (occurs when a time is already selected, but user is good)
* @param setup The current setup containing all settings, loggers, and user pools
* @throws CompletedException
* @throws TimeSlotTakenException
* @throws InterruptedException
* @throws UserNumberException
* @throws ReservationException
* @throws InvalidLoginException
*/
public static void run(WebDriver browser, User user, int offset, Setup setup)
throws CompletedException, TimeSlotTakenException, InterruptedException, UserNumberException,
ReservationException, InvalidLoginException, NotConnectedException
{
// Defines the wait
FluentWait<WebDriver> wait = new FluentWait<>(browser)
.withTimeout(20, TimeUnit.SECONDS)
.pollingEvery(500, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
// Steps through each run component
initiate(browser, wait);
login(browser, user);
setDate(browser, wait, setup.getSettings());
TimeTuple timeTuple = setTime(browser, offset, setup.getUserPool(), setup.getSettings());
selectRoom(browser, user, wait, setup.getSettings());
updateLog(user, setup.getUserPool(), timeTuple);
}
Example 8
Project: redsniff File: RedsniffWebDriverTester.java View source code | 6 votes |
/**
* Wait until the supplied {@link FindingExpectation} becomes satisfied, or throw a {@link TimeoutException}
* , using the supplied {@link FluentWait}
* This should only be done using a wait obtained by calling {@link #waiting()} to ensure the correct arguments are passed.
*
* @param expectation
* @param wait
* @return
*/
public <T, E, Q extends TypedQuantity<E, T>> T waitFor(
final FindingExpectation<E, Q, SearchContext> expectation, FluentWait<WebDriver> wait) {
try {
return new Waiter(wait).waitFor(expectation);
}
catch(FindingExpectationTimeoutException e){
//do a final check to get the message unoptimized
ExpectationCheckResult<E, Q> resultOfChecking = checker.resultOfChecking(expectation);
String reason;
if(resultOfChecking.meetsExpectation())
reason = "Expectation met only just after timeout. At timeout was:\n" + e.getReason();
else {
reason = resultOfChecking.toString();
//if still not found first check there isn't a page error or something
defaultingChecker().assertNoUltimateCauseWhile(newDescription().appendText("expecting ").appendDescriptionOf(expectation));
}
throw new FindingExpectationTimeoutException(e.getOriginalMessage(), reason, e);
}
}
Example 9
Project: easycukes File: SeleniumHelper.java View source code | 6 votes |
/**
* @param driver
* @param by
* @return
*/
public static WebElement waitForElementToBePresent(@NonNull final WebDriver driver,
@NonNull final By by) {
final FluentWait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
.pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
return wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver webDriver) {
try {
if (webDriver.findElement(by).isDisplayed())
return webDriver.findElement(by);
return null;
} catch (final ElementNotVisibleException e) {
return null;
}
}
});
}
Example 10
Project: easycukes File: SeleniumHelper.java View source code | 6 votes |
/**
* @param text
*/
public static void waitUntilTextIsSelected(@NonNull final WebDriver driver,
@NonNull final By by, @NonNull final String text) {
final FluentWait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS)
.pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver webDriver) {
final WebElement webElement = webDriver.findElement(by);
new Select(webElement).selectByVisibleText(text);
return webElement;
}
});
}
Example 11
Project: Testy File: WebLocatorDriverExecutor.java View source code | 6 votes |
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;
}
Example 12
Project: carina File: ToastDetector.java View source code | 6 votes |
private void waitForToast() {
LOGGER.info("Wait for toast...");
isPresent = false;
FluentWait<WebDriver> fluentWait = new FluentWait<>(webDriver);
fluentWait.withTimeout(waitTimeout, TimeUnit.SECONDS).pollingEvery(300, TimeUnit.MILLISECONDS).until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver input) {
List<?> webElemenList = webDriver.findElements(By.xpath(String.format(TOAST_PATTERN, toastToWait)));
if (webElemenList.size() == 1) {
LOGGER.info("Toast with text present: " + toastToWait);
isPresent = true;
return true;
} else {
return false;
}
}
});
}
Example 13
Project: carina File: ExtendedWebElement.java View source code | 6 votes |
/**
* 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();
}
}
Example 14
Project: jwala File: JwalaUi.java View source code | 5 votes |
public void testForBusyIcon(final int showTimeout, final int hideTimeout) {
new FluentWait(driver).withTimeout(showTimeout, TimeUnit.SECONDS).pollingEvery(100, TimeUnit.MILLISECONDS)
.until(ExpectedConditions.numberOfElementsToBe(
By.xpath("//div[contains(@class, 'AppBusyScreen') and contains(@class, 'show')]"), 1));
// Please take note that when "display none" is re-inserted, the whitespace in between the attribute and the value is not there anymore e.g.
// display: none => display:none hence the xpath => contains(@style,'display:none')
new WebDriverWait(driver, hideTimeout)
.until(ExpectedConditions.numberOfElementsToBe(
By.xpath("//div[contains(@class, 'AppBusyScreen') and contains(@class, 'show')]"), 0));
}
Example 15
Project: POM_HYBRID_FRAMEOWRK File: WebUtilities.java View source code | 5 votes |
/**
* 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;
}
}
Example 16
Project: POM_HYBRID_FRAMEOWRK File: WebUtilities.java View source code | 5 votes |
/**
* Wait for element staleness.
*
* @param driver the driver
* @param element the element
* @return true, if successful
*/
public static boolean waitForElementStaleness(WebDriver driver, WebElement element) {
boolean staleStatus = new FluentWait<WebDriver>(driver)
.withTimeout(60, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.until(ExpectedConditions.stalenessOf(element));
return staleStatus;
}
Example 17
Project: WebAutomation_AllureParallel File: FluentWaiting.java View source code | 5 votes |
public static void waitUntillElementToBeSelected(int TotalTimeInSeconds, int PollingTimeInMilliseconds, WebElement Element)
{
FluentWait<WebDriver> SelectableWait = new FluentWait<WebDriver>(getWebDriver())
.withTimeout(TotalTimeInSeconds, TimeUnit.SECONDS)
.pollingEvery(PollingTimeInMilliseconds, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
SelectableWait.until(ExpectedConditions.elementToBeSelected(Element));
}
Example 18
Project: WebAutomation_AllureParallel File: FluentWaiting.java View source code | 5 votes |
public static void waitUntillElementToBeVisible(int TotalTimeInSeconds, int PollingTimeInMilliseconds, WebElement Element)
{
FluentWait<WebDriver> visibleWait = new FluentWait<WebDriver>(getWebDriver())
.withTimeout(TotalTimeInSeconds, TimeUnit.SECONDS)
.pollingEvery(PollingTimeInMilliseconds, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
visibleWait.until(ExpectedConditions.visibilityOf(Element));
}
Example 19
Project: WebAutomation_AllureParallel File: FluentWaiting.java View source code | 5 votes |
public static void waitUntillAlertWindowsPopUp(int TotalTimeInSeconds, int PollingTimeInMilliseconds)
{
FluentWait<WebDriver> alertWait = new FluentWait<WebDriver>(getWebDriver())
.withTimeout(TotalTimeInSeconds, TimeUnit.SECONDS)
.pollingEvery(PollingTimeInMilliseconds, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
alertWait.until(ExpectedConditions.alertIsPresent());
}
Example 20
Project: WebAutomation_AllureParallel File: FluentWaiting.java View source code | 5 votes |
public static void waitUntillVisibilityOfElements(int TotalTimeInSeconds, int PollingTimeInMilliseconds, List<WebElement> Elements)
{
FluentWait<WebDriver> visibleWait = new FluentWait<WebDriver>(getWebDriver())
.withTimeout(TotalTimeInSeconds, TimeUnit.SECONDS)
.pollingEvery(PollingTimeInMilliseconds, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
visibleWait.until(ExpectedConditions.visibilityOfAllElements(Elements));
}
Example 21
Project: WebAutomation_AllureParallel File: FluentWaiting.java View source code | 5 votes |
public static void waitForTitleToBe(int TotalTimeInSeconds, int PollingTimeInMilliseconds, String PageTitle)
{
FluentWait<WebDriver> titleWait = new FluentWait<WebDriver>(getWebDriver())
.withTimeout(TotalTimeInSeconds, TimeUnit.SECONDS)
.pollingEvery(PollingTimeInMilliseconds, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
titleWait.until(ExpectedConditions.titleContains(PageTitle));
}
Example 22
Project: qa-automation File: WebDriverUtils.java View source code | 5 votes |
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));
}
Example 23
Project: aet File: WaitForHelper.java View source code | 5 votes |
/**
* This helper method allows a Selenium WebDriver to wait until one or more ExpectedConditions are
* met. The WebDriver waits for each ExpectedCondition to be met in a sequence, probing the page
* every 500ms until the ExpectedCondition is met or the timeout limit is reached.
*
* @param webDriver The instance of a WebDriver navigating the page under test
* @param timeoutInSeconds The time after which waiting ends unless the ExpectedCondition is met
* earlier.
* @param expectedConditions One or more of ExpectedConditions that have to be met.
*/
public static CollectorStepResult waitForExpectedCondition(
WebDriver webDriver,
long timeoutInSeconds,
ExpectedCondition<?>... expectedConditions) {
FluentWait<WebDriver> wait = new FluentWait<>(webDriver).withTimeout(timeoutInSeconds,
TimeUnit.SECONDS).pollingEvery(500, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class, StaleElementReferenceException.class);
for (ExpectedCondition<?> expectedCondition : expectedConditions) {
wait.until(expectedCondition);
}
return CollectorStepResult.newModifierResult();
}
Example 24
Project: gridmize File: BaseCell.java View source code | 5 votes |
public void click() {
By bySelector = By.cssSelector(getFormatedSelector());
new FluentWait<WebDriver>(getDriver())
.withTimeout(5, TimeUnit.SECONDS)
.pollingEvery(100, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class)
.until(ExpectedConditions.elementToBeClickable(bySelector))
.click();
waitScreenLoader();
}
Example 25
Project: gridmize File: BaseCell.java View source code | 5 votes |
private void waitElementClose(String Css, int timeout) {
new FluentWait<WebDriver>(getDriver())
.withTimeout(100, TimeUnit.SECONDS)
.pollingEvery(100, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class)
.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(Css)));
}
Example 26
Project: brixen File: WaitForElementVisible.java View source code | 5 votes |
/**
* Polls the specified {@code WebElement} at the specified polling interval until it becomes visible or the
* polling timeout expires.
*
* @param element the {@code WebElement} that is expected to become visible
* @param pollingTimeout the polling timeout in seconds to poll the {@code WebElement} for visibility status
* @param pollingInterval the polling interval in seconds between checks for the visibility status of the
* {@code WebElement}
*/
public void accept(WebElement element, Integer pollingTimeout, Integer pollingInterval) {
new FluentWait<>(element)
.withTimeout(pollingTimeout, TimeUnit.SECONDS)
.pollingEvery(pollingInterval, TimeUnit.SECONDS)
.until((WebElement element1) -> {
try {
return element1.isDisplayed();
} catch(NoSuchElementException | StaleElementReferenceException e) {
return false;
}
});
}
Example 27
Project: brixen File: WaitForAlertNotPresent.java View source code | 5 votes |
public void accept(final WebDriver driver, final Integer pollingTimeoutInSeconds, final Integer
pollingIntervalInSeconds) {
new FluentWait<>(driver)
.withTimeout(pollingTimeoutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollingIntervalInSeconds, TimeUnit.SECONDS)
.until((WebDriver driver1) -> !(new IsAlertPresent().test(driver1)));
}
Example 28
Project: brixen File: WaitForJQueryToComplete.java View source code | 5 votes |
public void accept(final WebDriver driver, final Integer pollingTimeoutInSeconds, final Integer
pollingIntervalInSeconds) {
new FluentWait<>(driver)
.withTimeout(pollingTimeoutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollingIntervalInSeconds, TimeUnit.SECONDS)
.until((WebDriver driver1) -> {
return new IsJQueryComplete().test(driver1);
});
}
Example 29
Project: brixen File: WaitForElementNotVisible.java View source code | 5 votes |
/**
* Polls the specified {@code WebElement} at the specified polling interval until it becomes invisible or the
* polling timeout expires.
*
* @param element the {@code WebElement} that is expected to become invisible
* @param pollingTimeout the polling timeout in seconds to poll the {@code WebElement} for visibility status
* @param pollingInterval the polling interval in seconds between checks for the visibility status of the
* {@code WebElement}
*/
public void accept(WebElement element, Integer pollingTimeout, Integer pollingInterval) {
new FluentWait<>(element)
.withTimeout(pollingTimeout, TimeUnit.SECONDS)
.pollingEvery(pollingInterval, TimeUnit.SECONDS)
.until((WebElement element1) -> {
try {
return element1.isDisplayed();
} catch(NoSuchElementException | StaleElementReferenceException e) {
return true;
}
});
}
Example 30
Project: de.lgohlke.selenium-webdriver File: ErrorLoggingWebDriverEventListener.java View source code | 5 votes |
private boolean isExceptionFromFluentWait(Throwable throwable) {
if (!(throwable instanceof NoSuchElementException)) {
return false;
}
for (StackTraceElement stackTraceElement : throwable.getStackTrace()) {
if (FluentWait.class.getName().equals(stackTraceElement.getClassName())) {
return true;
}
}
return false;
}
Example 31
Project: che File: CodenvyEditor.java View source code | 5 votes |
private void waitJavaDocPopupSrcAttributeIsNotEmpty() {
new FluentWait<>(seleniumWebDriver)
.withTimeout(LOAD_PAGE_TIMEOUT_SEC * 2, SECONDS)
.pollingEvery(LOAD_PAGE_TIMEOUT_SEC / 2, SECONDS)
.ignoring(StaleElementReferenceException.class, NoSuchElementException.class)
.until(ExpectedConditions.attributeToBeNotEmpty(autocompleteProposalJavaDocPopup, "src"));
}
Example 32
Project: che File: CodenvyEditor.java View source code | 5 votes |
private String getElementSrcLink(WebElement element) {
FluentWait<WebDriver> srcLinkWait =
new FluentWait<WebDriver>(seleniumWebDriver)
.withTimeout(LOAD_PAGE_TIMEOUT_SEC, SECONDS)
.pollingEvery(500, MILLISECONDS)
.ignoring(StaleElementReferenceException.class, NoSuchElementException.class);
return srcLinkWait.until((ExpectedCondition<String>) driver -> element.getAttribute("src"));
}
Example 33
Project: che File: OrganizationListPage.java View source code | 5 votes |
private void waitForElementDisappearance(String xpath) {
FluentWait<SeleniumWebDriver> wait =
new FluentWait<>(seleniumWebDriver)
.withTimeout(REDRAW_UI_ELEMENTS_TIMEOUT_SEC, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILLISECONDS)
.ignoring(StaleElementReferenceException.class);
wait.until(
(Function<WebDriver, Boolean>)
driver -> {
List<WebElement> elements = seleniumWebDriver.findElements(By.xpath(xpath));
return elements.isEmpty() || !elements.get(0).isDisplayed();
});
}
Example 34
Project: che File: AddMember.java View source code | 5 votes |
private void waitForElementDisappearance(String xpath) {
FluentWait<WebDriver> wait =
new FluentWait<WebDriver>(seleniumWebDriver)
.withTimeout(REDRAW_UI_ELEMENTS_TIMEOUT_SEC, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILLISECONDS)
.ignoring(StaleElementReferenceException.class);
wait.until(
(Function<WebDriver, Boolean>)
driver -> {
List<WebElement> elements = seleniumWebDriver.findElements(By.xpath(xpath));
return elements.isEmpty() || elements.get(0).isDisplayed();
});
}
Example 35
Project: che File: AddMember.java View source code | 5 votes |
/**
* Wait for popup is attached to DOM and animation ends.
*
* @param xpath xpath to match the 'che-popup' element
*/
private void waitForPopupAppearence(String xpath) {
FluentWait<WebDriver> wait =
new FluentWait<WebDriver>(seleniumWebDriver)
.withTimeout(REDRAW_UI_ELEMENTS_TIMEOUT_SEC, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILLISECONDS)
.ignoring(StaleElementReferenceException.class);
Map<String, Integer> lastSize = new HashMap<>();
lastSize.put("height", 0);
lastSize.put("width", 0);
wait.until(
(Function<WebDriver, Boolean>)
driver -> {
List<WebElement> elements = seleniumWebDriver.findElements(By.xpath(xpath));
if (elements.isEmpty()) {
return false;
}
Dimension size = elements.get(0).getSize();
if (lastSize.get("height") < size.getHeight()
|| lastSize.get("width") < size.getHeight()) {
lastSize.put("height", size.getHeight());
lastSize.put("width", size.getWidth());
return false;
}
return true;
});
}
Example 36
Project: che File: PullRequestPanel.java View source code | 5 votes |
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();
}
Example 37
Project: che File: Consoles.java View source code | 5 votes |
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();
}
Example 38
Project: che File: CommandsToolbar.java View source code | 5 votes |
/** wait appearance of process timer on commands toolbar and try to get value of the timer */
public String getTimerValue() {
Wait<WebDriver> wait =
new FluentWait<WebDriver>(seleniumWebDriver)
.withTimeout(REDRAW_UI_ELEMENTS_TIMEOUT_SEC, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILLISECONDS)
.ignoring(StaleElementReferenceException.class);
return wait.until(driver -> driver.findElement(By.id(Locators.TIMER_LOCATOR)).getText());
}
Example 39
Project: che File: Swagger.java View source code | 5 votes |
/** expand 'workspace' item */
private void expandWorkSpaceItem() {
Wait fluentWait =
new FluentWait(seleniumWebDriver)
.withTimeout(LOAD_PAGE_TIMEOUT_SEC, SECONDS)
.pollingEvery(MINIMUM_SEC, SECONDS)
.ignoring(StaleElementReferenceException.class, NoSuchElementException.class);
fluentWait.until((ExpectedCondition<Boolean>) input -> workSpaceLink.isEnabled());
workSpaceLink.click();
}
Example 40
Project: che File: JavaTestRunnerPluginConsole.java View source code | 5 votes |
/**
* Wait single method in the result tree marked as failed (red color).
*
* @param nameOfFailedMethods name of that should fail
*/
public void waitMethodMarkedAsFailed(String nameOfFailedMethods) {
FluentWait<WebDriver> wait =
new FluentWait<WebDriver>(seleniumWebDriver)
.withTimeout(ATTACHING_ELEM_TO_DOM_SEC, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILLISECONDS)
.ignoring(NotFoundException.class, StaleElementReferenceException.class);
String xpathToExpectedMethod = "//span[@id='%s']/following-sibling::*/div[text()='%s']";
wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.xpath(
String.format(
xpathToExpectedMethod, METHODS_MARKED_AS_FAILED, nameOfFailedMethods))));
}
相關推薦
selenium 顯示等待例項 org.openqa.selenium.support.ui.FluentWait
Example 1 Project: easycukes File: SeleniumHelper.java View source code 7 votes /** * @param by * @return */ public sta
Selenium firefox不相容org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.
使用firefox 28,selenium2.35.0時,報錯 org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 af
selenium 顯示等待
tor dom 固定 except https select 著作權 不可見 pre Explicit Waits(顯示等待) 顯示等待的代碼定義了等待條件,只有該條件觸發,才執行後續代碼。最垃圾的顯示等待就是使用 time.sleep(),這種情況是指定了固定的等待時
org.openqa.selenium.NoSuchElementException: Unable to locate element
現象:出現報錯org.openqa.selenium.NoSuchElementException: Unable to locate element 原因:進入網頁時,網頁可能在loading中,因此找不到元素。 解決方法:你可以讓他休眠Thread.sleep(2000),即休眠2秒,應
appium解決無法通過name屬性識別元素org.openqa.selenium.InvalidSelectorException: Locator Strategy 'name' is not supported for this session
執行程式碼、: public AndroidDriver<AndroidElement> appiumDriver; appiumDriver.findElement(By.name("我的")).click(); 報錯如下: 去到appium安裝目錄下,找到appiu
解決selenium啟動IE瀏覽器報錯:org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. Protected Mode settings are not the
環境:eclipse + java 1.8.0_121 + selenium-java-3.141.59 + IE 11 啟動IE程式碼: public void beforeMethod() { System.setProperty("webdriver.ie
org.openqa.selenium.NoSuchElementException: Unable to locate element: 異常解決方法
現象:出現報錯org.openqa.selenium.NoSuchElementException: Unable to locate element 原因:進入網頁時,網頁可能在loading中,因
Selenium+webDriver 啟動IE11 瀏覽器報錯“org.openqa.selenium.NoSuchWindowException”
Selenium2+webDriver 啟動IE11報錯 org.openqa.selenium.NoSuchWindowException: Unable to get browser (WARNING: The server did not provide any st
Appium報錯:org.openqa.selenium.NoSuchSessionException
程式碼: 客戶端程式碼中增加等待時間61秒 Thread.sleep(61000); 報錯: org.openqa.selenium.NoSuchSessionException 原因: Appium一個應用的session過期時間是60秒。 解決: 方法1.別超過
selenium 顯示等待,隱士等待
顯式等待是,先於程式碼的繼續執行,而定義的等待某個條件發生的程式碼。最糟糕的情況是Thread.sleep(),設定條件為一個需要等待的精確時間段。有一些提供的便利方法,可以幫助你編寫程式碼僅僅等待需要的時間。WebDriverWait與ExpectedCondition的結合是一種可以完成這個目標的方式。
Selenium顯示等待和隱式等待
1、selenium的顯示等待原理:顯示等待,就是明確的要等到某個元素的出現或者是某個元素的可點選等條件,等不到,就一直等,除非在規定的時間之內都沒找到,那麼久跳出Exception(簡而言之,就是直到元素出現才去操作,如果超時則報異常)WebDriverWait(drive
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055
Selenium 和 Firefox 版本不相容的問題解決 在網上找了很久,雖然都說是版本問題,建議降低 Firefox 的版本,或者是升級 Selenium的版本,照著他們的匹配方案,都沒有解決我的
Appium執行報錯java.lang.NoSuchMethodError: org.openqa.selenium.remote.HttpCommandExecutor.
第一次使用appium,執行Java指令碼總是報錯:java.lang.NoSuchMethodError:org.openqa.selenium.remote.HttpCommandExecutor.…… 導致driver = new AndroidDriver(new
selenium中的顯示等待,隱示等待,強制等待
一段 elf family 就會 周期 輸入 cit csdn AD 我們在實際使用selenium或者appium時,等待下個等待定位的元素出現,特別是web端加載的過程,都需要用到等待,而等待方式的設置是保證腳本穩定有效運行的一個非常重要的手段,在seleni
selenium的顯示等待和隱式等待區別
點擊 text 異常 exce 自己 設置 font gpo drive 1.selenium的顯示等待原理:顯式等待,就是明確的要等到某個元素的出現或者是某個元素的可點擊等條件,等不到,就一直等,除非在規定的時間之內都沒找到,那麽就跳出Exception.(簡而言之:就是
selenium webdriver顯示等待時間
ceo 單擊 con click sentinel 條件 new text 操作 當頁面加載很慢時,推薦使用顯示等待:等到需要操作的那個元素加載成功之後就直接操作這個元素,不需要等待其他元素的加載 WebDriverWait wait = new WebDriverWai
selenium的顯示等待和隱式等待的區別
指定 als 等待時間 可選 cli val 執行 cond BE 什麽是顯示等待和隱式等待?顯示等待就是有條件的等待隱式等待就是無條件的等待隱式等待 當使用了隱式等待執行測試的時候,如果 WebDriver沒有在 DOM中找到元素,將繼續等待,超出設定時間後則拋出找不到元
【selenium】 隱式等待與顯示等待
簡介:總結selenium的隱式等待與顯式等待 隱式等待 設定一個預設的操作等待時間,即每個操作的最大延時不超過該時間 常用的隱式等待 //頁面載入超時時間 driver.manage().timeouts().pageLoadTimeout(40, Tim
Selenium學習9--顯示等待,判斷頁面元素是否存在
html程式碼如下: <html lang="en"> <head> <title>your favorite fruits</title> </head> <body> <p&g
[selenium] selenium+java+TestNG 自定義顯示等待
package APItest; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; impo