當前位置: 首頁>>代碼示例>>Java>>正文


Java WebDriverWait類代碼示例

本文整理匯總了Java中org.openqa.selenium.support.ui.WebDriverWait的典型用法代碼示例。如果您正苦於以下問題:Java WebDriverWait類的具體用法?Java WebDriverWait怎麽用?Java WebDriverWait使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebDriverWait類屬於org.openqa.selenium.support.ui包,在下文中一共展示了WebDriverWait類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: switchFrame

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
private void switchFrame(String frameData) {
    try {
        if (frameData != null && !frameData.trim().isEmpty()) {
            driver.switchTo().defaultContent();
            if (frameData.trim().matches("[0-9]+")) {
                driver.switchTo().frame(Integer.parseInt(frameData.trim()));
            } else {
                WebDriverWait wait = new WebDriverWait(driver,
                        SystemDefaults.waitTime.get());
                wait.until(ExpectedConditions
                        .frameToBeAvailableAndSwitchToIt(frameData));
            }

        }
    } catch (Exception ex) {
        //Error while switching to frame
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:19,代碼來源:AutomationObject.java

示例2: run

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
@Override
public void run() {
    super.run();

    By locator = this.readLocatorArgument("locator");

    this.waitForAsyncCallsToFinish();

    try {
        WebElement element = this.getElement(locator);
        WebDriverWait wait = new WebDriverWait(this.driver, this.explicitWaitSec);
        wait.until(ExpectedConditions.elementToBeClickable(element));

        element.clear();
    } catch (Exception ex) {
        throw new RuntimeException(String.format(
                "Failed clicking on element %s",
                locator), ex);
    }
}
 
開發者ID:mcdcorp,項目名稱:opentest,代碼行數:21,代碼來源:ClearContent.java

示例3: waitWithContentAndDelayed

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
/**
 * 根據內容中包含某個子串來等待
 * @param content 內容子串
 * @param timeOutInMillis 超時時間毫秒數
 * @param delayedMillis 延遲毫秒數
 */
public void waitWithContentAndDelayed(final String content, int timeOutInMillis, int delayedMillis) {
    (new WebDriverWait(this, timeOutInMillis/1000)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            String html = d.getPageSource();
            if (StringUtils.isEmpty(content)) {
                //等到有內容就停止
                return StringUtils.isNotBlank(html);
            }
            return html != null && html.contains(content);
        }
    });
    if (delayedMillis > 0) {
        sleep(delayedMillis);
    }
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:22,代碼來源:WebDriverEx.java

示例4: swipeAndCheckElementVisible

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
protected void swipeAndCheckElementVisible(By locator, String direction) {
    Logger.trace(String.format("AppiumTestAction.swipeAndCheckElementVisible (%s, %s)",
            locator,
            direction));

    if (direction.equalsIgnoreCase("none")) {
        WebDriverWait wait = new WebDriverWait(driver, AppiumHelper.getExplicitWaitSec());
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    } else {
        // TODO: Revisit this and implement a smarter algorithm - not ok to repeat this for an arbitrary number of times
        int maxSwipeCount = Integer.valueOf(AppiumTestAction.config.getString("appium.maxSwipeCount", "50"));

        for (int i = 0; i < maxSwipeCount; i++) {
            try {
                Logger.trace(String.format("AppiumTestAction.swipeAndCheckElementVisible iteration %s", i + 1));
                waitForElementVisible(locator, 1);
                return;
            } catch (Exception ex) {
                swipe(direction);
            }
        }

        throw new RuntimeException(String.format("Element was not visible: %s", locator.toString()));
    }
}
 
開發者ID:mcdcorp,項目名稱:opentest,代碼行數:26,代碼來源:AppiumTestAction.java

示例5: editANodeWithEditor

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
public void editANodeWithEditor() throws Throwable {
    System.err.println("Ignore the following NPE. The DynamicTree class has a bug");
    WebElement tree = page.getTree();
    tree.click();
    final WebElement root = tree.findElement(By.cssSelector(".::root"));
    AssertJUnit.assertEquals("Root Node", root.getText());
    WebElement editor = root.findElement(By.cssSelector(".::editor"));
    editor.clear();
    editor.sendKeys("Hello World", Keys.ENTER);
    root.submit();
    new WebDriverWait(driver, 3).until(new Function<WebDriver, Boolean>() {
        @Override public Boolean apply(WebDriver input) {
            return root.getText().equals("Hello World");
        }
    });
    AssertJUnit.assertEquals("Hello World", root.getText());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:18,代碼來源:JTreeDynamicTreeTest.java

示例6: expandTree

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
public void expandTree() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals("false", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(root, "expanded", "true"));
    AssertJUnit.assertEquals("true", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
    WebElement node1 = tree.findElement(By.cssSelector(".::nth-node(2)"));
    AssertJUnit.assertEquals("Parent 1", node1.getText());
    new Actions(driver).doubleClick(node1).perform();
    WebElement node2 = tree.findElement(By.cssSelector(".::nth-node(3)"));
    AssertJUnit.assertEquals("Child 1", node2.getText());
    WebElement node3 = tree.findElement(By.cssSelector(".::nth-node(4)"));
    AssertJUnit.assertEquals("Child 2", node3.getText());
    WebElement node4 = tree.findElement(By.cssSelector(".::nth-node(5)"));
    AssertJUnit.assertEquals("Parent 2", node4.getText());
    new Actions(driver).doubleClick(node4).perform();
    WebElement node5 = tree.findElement(By.cssSelector(".::nth-node(6)"));
    AssertJUnit.assertEquals("Child 1", node5.getText());
    WebElement node6 = tree.findElement(By.cssSelector(".::nth-node(7)"));
    AssertJUnit.assertEquals("Child 2", node6.getText());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:26,代碼來源:JTreeDynamicTreeTest.java

示例7: doCreditCardPaymentOnPaymentPanel

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
private void doCreditCardPaymentOnPaymentPanel(Payment response) {
	RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
	driver.findElement(By.name("selCC|VISA")).click();
	WebDriverWait wait = new WebDriverWait(driver, 20);
	wait.until(ExpectedConditions.elementToBeClickable(By.id("cardnumber")));
	
	driver.findElement(By.id("cardnumber")).sendKeys("4444333322221111");
	driver.findElement(By.id("cvc")).sendKeys("123");
	(new Select(driver.findElement(By.id("expiry-month")))).selectByValue("05");
	(new Select(driver.findElement(By.id("expiry-year")))).selectByValue(getYear());
	driver.findElement(By.name("profile_id")).sendKeys("x");
	
	
	driver.findElement(By.id("right")).click();
	wait.until(ExpectedConditions.elementToBeClickable(By.id("right")));
	driver.findElement(By.id("right")).click();
}
 
開發者ID:mpay24,項目名稱:mpay24-java,代碼行數:18,代碼來源:TestRecurringPayments.java

示例8: testShippingAddressWithStreet2

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
@Test
public void testShippingAddressWithStreet2() throws PaymentException {
	Payment response = mpay24.paymentPage(getTestPaymentRequest(), getCustomerWithAddress("Coconut 3"));
	assertSuccessfullResponse(response);
	
	RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
	driver.findElement(By.name("selPAYPAL|PAYPAL")).click();
	WebDriverWait wait = new WebDriverWait(driver, 20);
	wait.until(ExpectedConditions.elementToBeClickable(By.name("BillingAddr/Street"))); 
	assertEquals("Testperson-de Approved", driver.findElement(By.name("BillingAddr/Name")).getAttribute("value"));
	assertEquals("Hellersbergstraße 14", driver.findElement(By.name("BillingAddr/Street")).getAttribute("value"));
	assertEquals("Coconut 3", driver.findElement(By.name("BillingAddr/Street2")).getAttribute("value"));
	assertEquals("41460", driver.findElement(By.name("BillingAddr/Zip")).getAttribute("value"));
	assertEquals("Neuss", driver.findElement(By.name("BillingAddr/City")).getAttribute("value"));
	assertEquals("Ankeborg", driver.findElement(By.name("BillingAddr/State")).getAttribute("value"));
	assertEquals("Deutschland", driver.findElement(By.name("BillingAddr/Country/@Code")).findElement(By.xpath("option[@selected='']")).getText());
}
 
開發者ID:mpay24,項目名稱:mpay24-java,代碼行數:18,代碼來源:TestPaymentPanel.java

示例9: swipeAndCheckElementNotVisible

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
protected void swipeAndCheckElementNotVisible(By locator, String direction) {
    Logger.trace(String.format("AppiumTestAction.swipeAndCheckElementNotVisible (%s, %s)",
            locator,
            direction));

    if (direction.equalsIgnoreCase("none")) {
        WebDriverWait wait = new WebDriverWait(driver, AppiumHelper.getExplicitWaitSec());
        wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));
    } else {
        // TODO: Revisit this and implement a smarter algorithm - not ok to repeat this for an arbitrary number of times
        int maxSwipeCount = Integer.valueOf(AppiumTestAction.config.getString("appium.maxSwipeCount", "50"));

        for (int i = 0; i < maxSwipeCount; i++) {
            try {
                Logger.trace(String.format("AppiumTestAction.swipeAndCheckElementVisible iteration %s", i + 1));
                waitForElementVisible(locator, 1);
                throw new RuntimeException(String.format("Element was found to be visible: %s", locator.toString()));
            } catch (Exception ex) {
                swipe(direction);
            }
        }
    }
}
 
開發者ID:mcdcorp,項目名稱:opentest,代碼行數:24,代碼來源:AppiumTestAction.java

示例10: waitForElements

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
protected void waitForElements(BasePage page, final WebElement... elements) {
	new WebDriverWait(getDriverProxy(), 40)
	.withMessage("Timed out navigating to [" + page.getClass().getName() + "]. Expected elements were not found. See screenshot for more details.")
	.until((WebDriver d) -> {
		for (WebElement elm : elements) {
			try {
				elm.isDisplayed();
			} catch (NoSuchElementException e) {
				// This is expected exception since we are waiting for the selenium element to come into existence.
				// This method will be called repeatedly until it reaches timeout or finds all selenium given.
				return false;
			}
		}
		return true;
	});
}
 
開發者ID:3pillarlabs,項目名稱:AutomationFrameworkTPG,代碼行數:17,代碼來源:BasePage.java

示例11: beforeSuiteMethod

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
@BeforeClass
public static void beforeSuiteMethod() throws Exception {

	// browser selection is hard-coded

	System.err.println("os: " + osName);
	if (osName.startsWith("windows")) {
		driver = BrowserDriver.initialize(browser);
	} else if (osName.startsWith("mac")) {
		driver = BrowserDriver.initialize("safari");
	} else {
		driver = BrowserDriver.initialize("firefox");
	}
	driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
	wait = new WebDriverWait(driver, flexibleWait);
	wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
	actions = new Actions(driver);
}
 
開發者ID:sergueik,項目名稱:SWET,代碼行數:19,代碼來源:SwetTest.java

示例12: visit

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
@Override
public void visit(WebDriver driver, String url) {

    final int implicitWait = Integer.parseInt(properties.getProperty("caching.page_load_wait"));
    driver.manage().timeouts().implicitlyWait(implicitWait, TimeUnit.SECONDS);
    driver.get(url);
    LOGGER.fine("Wait for JS complete");
    (new WebDriverWait(driver, implicitWait)).until((ExpectedCondition<Boolean>) d -> {
        final String status = (String) ((JavascriptExecutor) d).executeScript("return document.readyState");
        return status.equals("complete");
    });
    LOGGER.fine("JS complete");


    LOGGER.fine("Wait for footer");
    (new WebDriverWait(driver, implicitWait))
            .until(
                    ExpectedConditions.visibilityOf(
                            driver.findElement(By.name("downarrow"))));
    LOGGER.info("Footer is there");
    try {
        Thread.sleep(implicitWait * 1000l);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
 
開發者ID:italia,項目名稱:daf-cacher,代碼行數:27,代碼來源:MetabaseSniperPageImpl.java

示例13: waitForPageToLoad

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
protected Boolean waitForPageToLoad() {
    JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
    WebDriverWait wait = new WebDriverWait(driver, 10); //give up after 10 seconds

    //keep executing the given JS till it returns "true", when page is fully loaded and ready
    return wait.until((ExpectedCondition<Boolean>) input -> {
        String res = jsExecutor.executeScript("return /loaded|complete/.test(document.readyState);").toString();
        return Boolean.parseBoolean(res);
    });
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:11,代碼來源:PageObject.java

示例14: setUp

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
@BeforeClass//Аннотация Junit. Говорит, что метод должен запускаться каждый раз после создания экземпляра класса, перед всеми тестами
    public static void setUp() {
        //Устанавливаем System Property, чтобы наше приложени смогло найти драйвер
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Java\\geckodriver.exe");
        //Инициализируем драйвер
//        driver = new FirefoxDriver();
        driver = DriverManager.getDriver();
        //Инициализируем Implicit Wait
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //инициализируем Explicit Wait
        wait = new WebDriverWait(driver, 10);
    }
 
開發者ID:biblelamp,項目名稱:QAExercises,代碼行數:13,代碼來源:MatrixBoardTest.java

示例15: waitWithTitle

import org.openqa.selenium.support.ui.WebDriverWait; //導入依賴的package包/類
/**
 * 根據標題中包含某個子串來等待
 * @param title 標題子串
 * @param timeOutInMillis 超時時間毫秒數
 */
public void waitWithTitle(final String title, int timeOutInMillis) {
    (new WebDriverWait(this, timeOutInMillis/1000)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            String t = d.getTitle();
            if (StringUtils.isEmpty(title)) {
                //等到有title就停止
                return StringUtils.isNotBlank(t);
            }
            return t != null && t.contains(title);
        }
    });
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:18,代碼來源:WebDriverEx.java


注:本文中的org.openqa.selenium.support.ui.WebDriverWait類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。