Refine search
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); }
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; } }
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"))); }
@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")); } }
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(); }
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();
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();
@Test public void hideKeyboardWithParametersTest() { new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(By.id("IntegerA"))) .click(); driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done"); }
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();
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();
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)); }
/** * 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(); } }
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; } }
/** * 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)); }
@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); } }); }
@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()); }
public void delete(WebDriver driver) { deleteButton.click(); WebDriverWait wait = new WebDriverWait(driver, 2); wait.until(ExpectedConditions.alertIsPresent()); Alert alert = driver.switchTo().alert(); alert.accept(); } }
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"));
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)); } }
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']"))));