本文整理汇总了Java中org.openqa.selenium.support.ui.WebDriverWait.until方法的典型用法代码示例。如果您正苦于以下问题:Java WebDriverWait.until方法的具体用法?Java WebDriverWait.until怎么用?Java WebDriverWait.until使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.support.ui.WebDriverWait
的用法示例。
在下文中一共展示了WebDriverWait.until方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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()));
}
}
示例2: 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);
});
}
示例3: atc
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
public void atc() {
WebDriverWait wait = new WebDriverWait(driver, 300L);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@class='ffSelectButton' and (.//span[text()[contains(.,'Size')]] or .//span[text()[contains(.,'size')]])]")));
int index = new Random().nextInt(sizes.length);
String sizeToPick = Double.toString(sizes[index]);
for(WebElement e : driver.findElements(By.xpath("//div[@class='ffSelectMenuMid' and .//ul[.//li[.//span[text()[contains(.,'size')]]]]]/ul/li"))) {
String size = e.getText().trim();
if(size != null && size.equals(sizeToPick)) {
e.click();
break;
}
}
}
示例4: switchToNewWindow
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
@Override
public void switchToNewWindow() {
WebDriver driver = webPage.getDriver();
baseWindowHandle = driver.getWindowHandle();
Thucydides.getCurrentSession().put("baseWindowHandle",
baseWindowHandle);
Set<String> openedWindows = driver.getWindowHandles();
String newWindow = null;
if (openedWindows.size() > 1 && openedWindows.remove
(baseWindowHandle)) {
Iterator<String> openedWindowsIterator = openedWindows.iterator();
newWindow = openedWindowsIterator.next();
} else {
int timeout = getSatisfyWebProperties().getSatisfyWait();
WebDriverWait wait = new WebDriverWait(driver, timeout);
newWindow = wait.until(anyWindowOtherThan(openedWindows));
}
driver.switchTo().window(newWindow);
}
示例5: explicitWait
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
/**
* This method makes the driver wait till the webelement is located
**/
public static void explicitWait(WebElement wb, WebDriver driver) {
try {
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOf(wb));
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: isAlertPresent
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
public boolean isAlertPresent() {
WebDriverWait wait = new WebDriverWait(driver, 0);
try {
wait.until(ExpectedConditions.alertIsPresent());
return true;
} catch (Exception e) {
return false;
}
}
示例7: switchTo
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
/**
* 等待frame可以用,切换到指定的frame
*
* @param by
*/
public void switchTo(By frameby) {
WebDriverWait webDriverWait = new WebDriverWait(driver, DRIVER_WAIT_TIMEOUT_IN_SECOND);
try {
// wait and switchTo, Otherwise, throws a TimeoutException
webDriverWait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameby));
// driver.switchTo().frame(this.findElement(frameby));
LogUtil.info(driver.manage().logs() + "==>switchTo frame:" + frameby.toString() + "成功.");
} catch (Exception e) {
this.screenShot();
LogUtil.info(driver.manage().logs() + "==>switchTo frame:" + frameby.toString() + "等待超时!");
driver.switchTo().frame(this.findElement(frameby)); // 与waituntil功能重复,但until经常失败,为了增强健壮性才如此写
}
}
示例8: SettingsViewButton
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
@Test
public void SettingsViewButton() {
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement menuButton = driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"Open navigation\"]"));
menuButton.click();
WebElement settingsViewButton = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Settings\"]"))));
settingsViewButton.click();
}
示例9: click
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
/**
* Click on an element.
*
* @param locator
* - element locator
* @param replacement
* - if element contains dynamic part, i.e. '$value' in locator
* part, then '$value' part will be replaced by replacement value
* @param ignoreNoSuchElementException
* - if set to true, then no exceptions will be thrown when
* element is not found, Suitable for situations where you want
* the test to progress despite of the result that click action
* succeeded or not!
* @throws PropertyNotFoundException
* - throw this exception when declared locator is not found in
* object repository
* @throws InvalidLocatorStrategyException
* - throw this exception when locator strategy is wrong. Valid
* locator strategies are 'ID', 'XPATH', 'NAME', 'CSS_SELECTOR',
* 'CLASS_NAME', 'LINK_TEXT', 'PARTIAL_LINK_TEXT' and 'TAG_NAME'
*/
public void click(String locator, String replacement, boolean ignoreNoSuchElementException)
throws PropertyNotFoundException, InvalidLocatorStrategyException
{
if (replacement != null)
{
if (locator.contains("$value"))
{
locator = locator.replace("$value", replacement);
}
}
if (ignoreNoSuchElementException)
{
try
{
element = ElementFinder.findElement(driver, locator);
} catch (NoSuchElementException ex)
{
return;
}
} else
{
element = ElementFinder.findElement(driver, locator);
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(element));
element.click();
LOGGER.info("Successfully clicked on element '" + locator + "' with locator value '"
+ props.getProperty(locator) + "'");
}
}
示例10: isAlertPresent
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
/**
* Check for alert presence.
*
* @return - true if an alert is present
*/
public boolean isAlertPresent(){
boolean foundAlert = false;
// check for alert presence with no timeout (0 seconds)
WebDriverWait wait = new WebDriverWait(driver, 0);
try {
wait.until(ExpectedConditions.alertIsPresent());
foundAlert = true;
} catch (TimeoutException eTO) {
foundAlert = false;
}
return foundAlert;
}
示例11: OverViewButton
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
@Test
public void OverViewButton() {
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement menuButton = driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"Open navigation\"]"));
menuButton.click();
WebElement overViewButton = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Overview\"]"))));
overViewButton.click();
}
示例12: waitForPageToLoad
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
public void waitForPageToLoad()
{
JavaScriptHelper js = new JavaScriptHelper();
ExpectedCondition expectedCondition = new ExpectedCondition<Boolean>(){
public Boolean apply(WebDriver driver){
return js.executeScript( "return document.readyState" ).equals( "complete" );
}
};
WebDriverWait wait = new WebDriverWait(driver, SessionContextManager.getWaitForPageToLoad(), THREAD_SLEEP);
wait.until(expectedCondition);
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.tagName("div")));
}
示例13: waitForElementInvisibility
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
/**
* waitForElementInvisibility(java.lang.String, long)
*/
public void waitForElementInvisibility(String locator, long waitSeconds) {
try {
WebDriverWait wait = new WebDriverWait(driver, waitSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(determineLocator(locator)));
} catch (Exception e) {
takeScreenShot();
throw new TimeoutException("Exception has been thrown", e);
}
}
示例14: DescribeComponentPage
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
public DescribeComponentPage(WebDriver driver)
{
super(driver);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".component_name")));
}
示例15: explicitWaitElementToBeClickable
import org.openqa.selenium.support.ui.WebDriverWait; //导入方法依赖的package包/类
/** To Wait Until Element to be Clickable */
public static void explicitWaitElementToBeClickable(WebElement element, int time)
{
WebDriverWait clickableWait = new WebDriverWait(driver, time);
clickableWait.until(ExpectedConditions.elementToBeClickable(element));
}