List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait
public WebDriverWait(WebDriver driver, Duration timeout)
From source file:scormADL12.java
License:Open Source License
@Before public void setUp() { driver = new InternetExplorerDriver(); wait = new WebDriverWait(driver, 60); }
From source file:scormADL12.java
License:Open Source License
/** * Explicit wait for element with text/*from w w w . j a va 2 s . com*/ * @param locator * @param text * @return */ public WebElement waitElementWithTextPresent(final By locator, final String text) { return new WebDriverWait(driver, 30).until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver d) { WebElement e = d.findElement(locator); String elementText = e.getText(); if (elementText != null && elementText.contains(text)) { return e; } else { return null; } } }); }
From source file:BallerinaEditorUITest.java
License:Open Source License
private WebElement waitAndGetElementByXpath(WebDriver driver, String xpath) { WebDriverWait wait = new WebDriverWait(driver, 50); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath))); return driver.findElement(By.xpath(xpath)); }
From source file:scormADL2004.java
License:Open Source License
@Before public void setUp() throws IOException, InterruptedException { driver = new InternetExplorerDriver(); wait = new WebDriverWait(driver, 60); String testSuiteURL = System.getProperty("testSuiteURL"); String moodleURL = System.getProperty("moodleURL"); if (testSuiteURL == null) { throw new IOException("ADL SCORM 2004 Test Suite URL not specified"); }// w ww . j a v a2 s . c o m if (moodleURL == null) { throw new IOException("Moodle Test Site URL not specified"); } if (username1 == null) { username1 = "joestudent"; password1 = "joestudent"; } if (username2 == null) { username2 = "marylearner"; password2 = "marylearner"; } driver.get(testSuiteURL); // Overcome Selenium IE Page load Bug. driver.switchTo().frame("instructions"); wait.until(presenceOfElementLocated(By.id("New"))); ((JavascriptExecutor) driver).executeScript("newTest();"); wait.until(presenceOfElementLocated(By.id("pname"))); driver.findElement(By.id("pname")).sendKeys("Moodle"); driver.findElement(By.id("pversion")).sendKeys("2011033003"); driver.findElement(By.id("pvname")).sendKeys("MoodleHQ"); driver.switchTo().window(""); driver.switchTo().frame("controls"); driver.findElement(By.id("continue")).click(); driver.switchTo().window(""); driver.switchTo().frame("instructions"); wait.until(presenceOfElementLocated(By.id("learner1Name"))); driver.findElement(By.id("learner1Name")).sendKeys("Moodle Learner 1"); driver.findElement(By.id("learner1ID")).sendKeys(username1); driver.findElement(By.id("learner2Name")).sendKeys("Moodle Learner 2"); driver.findElement(By.id("learner2ID")).sendKeys(username2); driver.switchTo().window(""); driver.switchTo().frame("controls"); driver.findElement(By.id("continue")).click(); driver.switchTo().window(""); ((JavascriptExecutor) driver).executeScript("window.open('" + moodleURL + "', 'moodleWindow');"); driver.switchTo().window("moodleWindow"); }
From source file:CarTest1.java
@Test //Verify that page is loaded and all expected data are visible public void test1() throws Exception { (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement e = d.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(5)); return true; });/*from www. j a v a 2s .c o m*/ }
From source file:CarTest1.java
@Test //Clear text and verify 5 rows public void test3() throws Exception { tearDown();//from ww w. j a v a 2 s.com setup(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement e = d.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(5)); return true; }); }
From source file:CarTest1.java
@Test public void test5() throws Exception { WebElement row = driver.findElement(By.xpath("//tbody/tr[td='938']")); WebElement a = row.findElements(By.tagName("a")).get(0); a.click();//w w w .j av a2s .c o m WebElement desc = driver.findElement(By.name("description")); desc.clear(); desc.sendKeys("Cool car"); WebElement submit = driver.findElement(By.id("save")); submit.click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement newRow = d.findElement(By.xpath("//tbody/tr[td = '938']")); String b = newRow.findElements(By.tagName("td")).get(5).getText(); Assert.assertEquals("Cool car", b); return true; }); }
From source file:CarTest1.java
@Test public void test7() throws Exception { WebElement newCar = driver.findElement(By.id("new")); newCar.click();// w ww.ja va 2 s .c o m WebElement year = driver.findElement(By.name("year")); WebElement reg = driver.findElement(By.name("registered")); WebElement make = driver.findElement(By.name("make")); WebElement model = driver.findElement(By.name("model")); WebElement desc = driver.findElement(By.name("description")); WebElement price = driver.findElement(By.name("price")); WebElement submit = driver.findElement(By.id("save")); year.sendKeys("2008"); reg.sendKeys("2002-5-5"); make.sendKeys("Kia"); model.sendKeys("Rio"); desc.sendKeys("As new"); price.sendKeys("31000"); submit.click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement e = d.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(6)); return true; }); }
From source file:testTheClient.java
@Test public void domLoaded5RowsinTbody() { WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); });//w w w. j av a 2s .co m Assert.assertThat(tableBody.findElements(By.tagName("tr")).size(), is(5)); }
From source file:testTheClient.java
@Test public void lookUp2002() throws Exception { WebElement element = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return driver.findElement(By.xpath("//*[@id=\"filter\"]")); });/*from w ww. j a v a 2 s .c om*/ element.clear(); element.sendKeys("2002"); WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> rows = table.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(2)); }