当前位置: 首页>>代码示例>>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;未经允许,请勿转载。