本文整理了Java中org.openqa.selenium.support.ui.WebDriverWait
类的一些代码示例,展示了WebDriverWait
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebDriverWait
类的具体详情如下:
包路径:org.openqa.selenium.support.ui.WebDriverWait
类名称:WebDriverWait
[英]An implementation of the Wait interface that makes use of WebDriver. The expected usage is in conjunction with the ExpectedCondition interface.
Because waiting for elements to appear on a page is such a common use-case, this class will silently swallow NotFoundException whilst waiting.
[中]Wait接口的一个实现,它使用WebDriver。预期用途与ExpectedCondition接口结合使用。
因为等待元素出现在页面上是一种常见的用例,所以这个类在等待时会默默地吞下NotFoundException。
代码示例来源:origin: apache/geode
private void login() {
WebElement userNameElement = waitForElementById("user_name", 60);
WebElement passwordElement = waitForElementById("user_password");
userNameElement.sendKeys(username);
passwordElement.sendKeys(password);
passwordElement.submit();
driver.get(getPulseURL() + "clusterDetail.html");
WebElement userNameOnPulsePage =
(new WebDriverWait(driver, 30, 1000)).until(
(ExpectedCondition<WebElement>) d -> d.findElement(By.id("userName")));
assertNotNull(userNameOnPulsePage);
}
代码示例来源:origin: apache/geode
private WebElement waitForElementById(final String id, int timeoutInSeconds) {
WebElement element =
(new WebDriverWait(driver, timeoutInSeconds, 1000))
.until((ExpectedCondition<WebElement>) d -> d.findElement(By.id(id)));
assertNotNull(element);
return element;
}
}
代码示例来源:origin: testcontainers/testcontainers-java
protected void doSimpleWebdriverTest(BrowserWebDriverContainer rule) {
RemoteWebDriver driver = setupDriverFromRule(rule);
System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress());
System.out.println("VNC URL is: " + rule.getVncAddress());
driver.get("http://www.google.com");
WebElement search = driver.findElement(By.name("q"));
search.sendKeys("testcontainers");
search.submit();
List<WebElement> results = new WebDriverWait(driver, 15)
.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#search h3")));
assertTrue("the word 'testcontainers' appears in search results",
results.stream()
.anyMatch(el -> el.getText().contains("testcontainers")));
}
代码示例来源:origin: org.juzu/juzu-core
@Test
@RunAsClient
public void test() throws Exception {
driver.get(applicationURL().toString());
System.out.println(driver.getPageSource());
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html[@bar]")));
WebElement elt = driver.findElement(By.tagName("html"));
assertEquals("<bar>foo_value</bar>", elt.getAttribute("bar"));
}
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 300/*seconds*/);
driver.manage().window().maximize();
driver.get("http://www.bbc.com/");
for (int menu_item_module = 0; menu_item_module < 10; menu_item_module++) {
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By
.id("digitalVellum_dijit_MenuListItem_"
+menu_item_module)));
element.click();
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FireFoxDriver();
driver.get("http://172.16.16.219:9081/LOSWebApp/security/login.htm");
WebDriverWait wait = new WebDriverWait(driver, 3000);
wait.until(ExpectedConditions.visibilityOfElementLocated((By.name("ssoId"))));
WebElement userid = driver.findElement(By.name("ssoId"));
WebElement password = driver.findElement(By.name("password"));
WebElement loginButton = driver.findElement(By.name("button"));
userid.sendKeys("userID");
password.sendKeys("pwd");
loginButton.click();
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("https://play.google.com/store/apps/details?id=com.facebook.orca");
WebElement permission = driver.findElement(By.className("id-view-permissions-details"));
permission.click();
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement modalPopup = driver.findElement(By.className("modal-dialog"));
wait.until(ExpectedConditions.visibilityOf(modalPopup));
String xpath = "//ul[@class='bucket-description']//li[text()='precise location (GPS and network-based)']";
WebElement whatTheHeck = driver.findElement(By.xpath(xpath));
System.out.println(whatTheHeck.getText());
driver.quit();
代码示例来源:origin: appium/java-client
@Test public void hideKeyboardWithParametersTest() {
new WebDriverWait(driver, 30)
.until(ExpectedConditions.presenceOfElementLocated(By.id("IntegerA")))
.click();
driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done");
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("http://imgur.com/");
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.findElement(By.partialLinkText("sign in")).click();
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.className("cboxIframe")));
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("f")));
driver.findElement(By.name("username")).sendKeys("abcd");
driver.findElement(By.xpath(".//*[@id='password']/input")).sendKeys("abcd");
driver.close();
driver.quit();
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("http://curatorsofsweden.com/archive/");
By linkSelector = By.cssSelector("div[class='block block--archive'] a");
WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.presenceOfElementLocated(linkSelector));
List<WebElement> linkElements = driver.findElements(linkSelector);
for (WebElement linkElement : linkElements) {
String link = linkElement.getAttribute("href");
System.out.println("LINK " + link);
}
driver.quit();
代码示例来源:origin: ksahin/introWebScraping
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
System.setProperty("phantomjs.page.settings.userAgent", USER_AGENT);
String baseUrl = "https://www.inshorts.com/en/read" ;
initPhantomJS();
driver.get(baseUrl) ;
int nbArticlesBefore = driver.findElements(By.xpath("//div[@class='card-stack']/div")).size();
driver.findElement(By.id("load-more-btn")).click();
WebDriverWait wait = new WebDriverWait(driver, 30);
// We wait for the ajax call to fire and to load the response into the page
Thread.sleep(800);
int nbArticlesAfter = driver.findElements(By.xpath("//div[@class='card-stack']/div")).size();
System.out.println(String.format("Initial articles : %s Articles after clicking : %s", nbArticlesBefore, nbArticlesAfter));
}
代码示例来源:origin: TEAMMATES/teammates
/**
* Selects the visibility option and waits for the visibility message to load.
* <b>Note: </b> The custom visibility options allow for more customization after the option is selected and
* the visibility message would not be loaded until the custom options are modified, which implies that there is no need
* to wait for the visibility message to load if the custom visibility options is selected.
*/
public void clickVisibilityDropdownAndWaitForVisibilityMessageToLoad(String optionValue, int qnNumber) {
String customVisibilityOptionsValue = "OTHER";
// If the other option is selected, no AJAX request is made
if (!optionValue.equals(customVisibilityOptionsValue)) {
getjQueryAjaxHandler().waitForAjaxIfPresentThenRegisterHandlers();
}
WebElement visibilityOptionsDropdown =
browser.driver.findElement(By.cssSelector("#questionTable-" + qnNumber + " .visibility-options-dropdown"));
WebElement dropdownToggle = visibilityOptionsDropdown.findElement(By.tagName("button"));
scrollElementToCenterAndClick(dropdownToggle);
WebElement optionElement =
visibilityOptionsDropdown.findElement(By.cssSelector("a[data-option-name=\"" + optionValue + "\"]"));
// once the dropdown is assigned the class "open", the options should be visible unless not in the viewport
waitForElementToBeMemberOfClass(visibilityOptionsDropdown, "open");
// Scroll to the option because it may not be in the viewport
scrollElementToCenterAndClick(optionElement);
WebDriverWait wait = new WebDriverWait(browser.driver, TestProperties.TEST_TIMEOUT);
wait.until(ExpectedConditions.textToBePresentInElement(dropdownToggle, optionElement.getText()));
// If the other option is selected, no AJAX request is made
if (!optionValue.equals(customVisibilityOptionsValue)) {
getjQueryAjaxHandler().waitForRequestComplete();
}
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
String searchText = "Men's Outerwear";
driver.get("https://shop.polymer-project.org/");
WebDriverWait wait = new WebDriverWait(driver, 5);
List<WebElement> sections = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("div.item")));
for (WebElement section : sections)
{
if (section.getText().toLowerCase().contains(searchText.toLowerCase()))
{
section.findElement(By.linkText("SHOP NOW")).click();
break;
}
}
代码示例来源:origin: org.ligoj.bootstrap/bootstrap-web-test
/**
* Assert that the given select has the expected selected text
*
* @param by
* Select location
* @param expectedText
* Expected selected text
*/
protected void assertSelectedText(final String expectedText, final By by) {
new WebDriverWait(driver, timeout)
.until(d -> new Select(driver.findElement(by)).getFirstSelectedOption().getText().equals(expectedText));
}
代码示例来源:origin: la-team/light-admin
@Override
public void waitForElementVisible(final WebElement element, long timeout) {
new WebDriverWait(webDriver, timeout).until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return isElementPresent(element);
}
});
}
代码示例来源:origin: allure-examples/allure-junit-example
@Step
public void search(String text) {
driver.findElement(By.id("text")).sendKeys(text);
driver.findElement(By.className("suggest2-form__button")).submit();
new WebDriverWait(driver, 10)
.withMessage("Could not load results page")
.until(mainContainLoaded());
}
代码示例来源:origin: getgauge-examples/java-gradle-selenium
public void delete(WebDriver driver) {
deleteButton.click();
WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
}
}
代码示例来源:origin: stackoverflow.com
WebDriver driver = new FirefoxDriver();
driver.get("https://twitter.com/blakeshelton");
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement e = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("a[data-nav='followers']")));
System.out.println(e.getAttribute("outerHTML"));
System.out.println(e.getAttribute("title"));
代码示例来源:origin: uk.co.blackpepper.support/bp-support-selenium
public static void clear(WebDriver driver, String id) {
List<WebElement> elements = driver.findElements(byCloseChoices(id));
for (WebElement element : elements) {
element.click();
new WebDriverWait(driver, CLEAR_TIME_OUT).until(stalenessOf(element));
}
}
代码示例来源:origin: appium/java-client
final WebDriverWait wait = new WebDriverWait(driver, 30);
Activity activity = new Activity("io.appium.android.apis", ".view.PopupMenu1");
driver.startActivity(activity);
wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy
.AccessibilityId("Make a Popup!")));
MobileElement popUpElement = driver.findElement(MobileBy.AccessibilityId("Make a Popup!"));
wait.until(ExpectedConditions.elementToBeClickable(popUpElement)).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath(".//*[@text='Search']"))).click();
assertNotNull(wait.until(ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[@text='Clicked popup menu item Search']"))));
wait.until(ExpectedConditions.elementToBeClickable(popUpElement)).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath(".//*[@text='Add']"))).click();
assertNotNull(wait.until(ExpectedConditions
.presenceOfElementLocated(By.xpath("//*[@text='Clicked popup menu item Add']"))));
wait.until(ExpectedConditions.elementToBeClickable(popUpElement)).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath(".//*[@text='Edit']"))).click();
assertNotNull(wait.until(ExpectedConditions
.presenceOfElementLocated(By.xpath("//*[@text='Clicked popup menu item Edit']"))));
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath(".//*[@text='Share']"))).click();
assertNotNull(wait.until(ExpectedConditions
.presenceOfElementLocated(By.xpath("//*[@text='Clicked popup menu item Share']"))));
内容来源于网络,如有侵权,请联系作者删除!