List of usage examples for org.openqa.selenium WebElement click
void click();
From source file:be.rubus.web.jerry.initializer.RequiredInitializerTest.java
License:Apache License
@Test @RunAsClient/*from w ww . j av a 2 s . co m*/ public void testRequired() throws Exception { driver.get(new URL(contextPath, "validations.xhtml").toString()); WebElement submitButton = driver.findElement(By.id("test:submit")); submitButton.click(); Thread.sleep(1000); WebElement messages = driver.findElement(By.id("messages")); List<WebElement> errorElements = messages.findElements(By.tagName("li")); assertThat(errorElements).hasSize(1); assertThat(errorElements.get(0).getText()).contains("Validation Error: Value is required."); }
From source file:be.rubus.web.jerry.recording.RecordValueTest.java
License:Apache License
@Test @RunAsClient/*from ww w . j a va 2s. c om*/ public void testClassLevelValidation() throws Exception { driver.get(new URL(contextPath, "dateRange.xhtml").toString()); WebElement field = driver.findElement(By.id("test:beginDate")); field.sendKeys("01/03/2015"); field = driver.findElement(By.id("test:endDate")); field.sendKeys("01/01/2015"); WebElement submitButton = driver.findElement(By.id("test:submit")); submitButton.click(); Thread.sleep(1000); WebElement messages = driver.findElement(By.id("errors")); List<WebElement> errorElements = messages.findElements(By.tagName("li")); // FIXME The test fails and it seems that RecordingInfoPhaseListener doesn't kick in assertThat(errorElements).hasSize(1); assertThat(errorElements.get(0).getText()).contains("Validation Error: Value is required."); }
From source file:be.rubus.web.jerry.validation.FutureDateProviderTest.java
License:Apache License
@Test @RunAsClient//from w w w . j a v a 2 s . com public void testFuture() throws Exception { driver.get(new URL(contextPath, "future.xhtml").toString()); //By default, the date provider is using system date, so failures WebElement date1 = driver.findElement(By.id("test:date1")); date1.sendKeys("23/02/2015"); WebElement date2 = driver.findElement(By.id("test:date2")); date2.sendKeys("23/02/2015"); assertThat(date1.getAttribute("class")).doesNotContain("ui-state-error"); assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error"); WebElement btn = driver.findElement(By.id("test:submit")); btn.click(); WebElement errors = driver.findElement(By.id("errors")); List<WebElement> errorMessages = errors.findElements(By.tagName("li")); assertThat(errorMessages).hasSize(2); // Page is reloaded so elements are detached date1 = driver.findElement(By.id("test:date1")); date2 = driver.findElement(By.id("test:date2")); assertThat(date1.getAttribute("class")).contains("ui-state-error"); assertThat(date2.getAttribute("class")).contains("ui-state-error"); // Set date for DateProvider WebElement fixedNow = driver.findElement(By.id("date:fixedNow")); fixedNow.clear(); fixedNow.sendKeys("20/02/2015"); WebElement dateBtn = driver.findElement(By.id("date:setDate")); dateBtn.click(); date1 = driver.findElement(By.id("test:date1")); date1.sendKeys("23/02/2015"); date2 = driver.findElement(By.id("test:date2")); date2.sendKeys("23/02/2015"); btn = driver.findElement(By.id("test:submit")); btn.click(); errors = driver.findElement(By.id("errors")); errorMessages = errors.findElements(By.tagName("li")); assertThat(errorMessages).hasSize(1); // Only 1 error now // Page is reloaded so elements are detached date1 = driver.findElement(By.id("test:date1")); date2 = driver.findElement(By.id("test:date2")); assertThat(date1.getAttribute("class")).contains("ui-state-error"); assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error"); // The one withValFuture }
From source file:be.rubus.web.jerry.validation.FutureTest.java
License:Apache License
@Test @RunAsClient/*from w ww .j a v a 2s . c om*/ public void testFuture() throws Exception { driver.get(new URL(contextPath, "future_NoProvider.xhtml").toString()); WebElement date1 = driver.findElement(By.id("test:date1")); date1.sendKeys("23/02/2015"); WebElement date2 = driver.findElement(By.id("test:date2")); date2.sendKeys("23/02/2015"); WebElement btn = driver.findElement(By.id("test:submit")); btn.click(); WebElement errors = driver.findElement(By.id("errors")); List<WebElement> errorMessages = errors.findElements(By.tagName("li")); assertThat(errorMessages).hasSize(2); // Page is reloaded so elements are detached date1 = driver.findElement(By.id("test:date1")); date2 = driver.findElement(By.id("test:date2")); assertThat(date1.getAttribute("class")).contains("ui-state-error"); assertThat(date2.getAttribute("class")).contains("ui-state-error"); }
From source file:be.ugent.mmlab.webdriver.Demo.java
License:Apache License
public void demoTime() throws InterruptedException { // initialize web browser. WebDriver driver = new FirefoxDriver(); // go to the Belgian railways website driver.get("http://www.belgianrail.be"); // select "English" // HTML:// w w w . ja va 2 s . co m // <a // id="ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink" // href="javascript:__doPostBack('ctl00$bodyPlaceholder$languagesList$ctl02$languageNameLink','')" // > English </a> WebElement english = driver .findElement(By.id("ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink")); english.click(); // fill out departure WebElement from = driver.findElement(By.id("departureStationInput")); from.sendKeys("Gent-Dampoort"); // pause for a second to make it not too fast Thread.sleep(1000); // click in the field to get the auto-completion away from.click(); // fill out arrival WebElement to = driver.findElement(By.id("arrivalStationInput")); to.sendKeys("Brussel-Noord"); Thread.sleep(1000); to.click(); // click timetable button WebElement timetableButton = driver.findElement(By.id( "ctl00_ctl00_bodyPlaceholder_bodyPlaceholder_mobilityTimeTableSearch_HomeTabTimeTable1_submitButton")); timetableButton.click(); // get departure info // HTML: // <td headers="hafasOVTimeOUTWARD" class="time"> // <div> // <div class="planed overviewDep"> // 10:00 dep <span class="bold prognosis">+12 min.</span> // </div> // <div class="planed"> // 11:20 arr <span class="bold green">+0 min.</span> // </div> // </div> // </td> List<WebElement> timeCells = driver.findElements(By.className("time")); for (WebElement timeCell : timeCells) { List<WebElement> times = timeCell.findElements(By.className("planed")); System.out.println("----------------------------------------------"); System.out.println("departure time: " + times.get(0).getText()); System.out.println("arrival time: " + times.get(1).getText()); } }
From source file:bingbot.BingBot.java
/** * @param n number of searches to execute * @param file file to get user data from * @throws java.io.IOException//from ww w . jav a 2 s . c o m * @throws java.lang.InterruptedException */ public void search(int m, int n, File file) throws Exception { System.out.println("Search method entered..."); scanner = new Scanner(file); Scanner sc = new Scanner(new File("./files/dict")); String next = scanner.next(); String name = null; String password = null; while (!next.equals("END")) { name = next; password = scanner.next(); next = scanner.next(); } for (int k = 0; k < m; k++) { driver.get("http://live.com"); try { WebElement signout = driver.findElement(By.id("c_signout")); if (!signout.isDisplayed()) { return; } } catch (Exception e) { System.out.println("NO SUCH ELEMENT 'C_SIGNOUT'"); System.out.println("SIGNING IN"); } WebElement username = driver.findElement(By.id("i0116")); username.sendKeys(name); WebElement userpassword = driver.findElement(By.id("i0118")); userpassword.sendKeys(password); WebElement signin = driver.findElement(By.id("idSIButton9")); signin.click(); Thread.sleep(10000); for (int j = 0; j < 41238; j++) { String word = sc.next(); list[j] = word; } for (int i = 0; i < n; i++) { Random rand = new Random(); driver.get("https://bing.com/"); WebElement query = driver.findElement(By.id("sb_form_q")); query.sendKeys(list[rand.nextInt(41238)]); WebElement go = driver.findElement(By.id("sb_form_go")); go.click(); Thread.sleep(rand.nextInt(5000) + 5000); } } seleniumServer.stop(); }
From source file:bingbot.BingBot.java
public void searchMobile(int m, int n, File file) throws Exception { System.out.println("Search method entered..."); scanner = new Scanner(file); Scanner sc = new Scanner(new File("./files/dict")); String next = scanner.next(); String name = null;//from ww w. j a va2 s . co m String password = null; while (!next.equals("END")) { name = next; password = scanner.next(); next = scanner.next(); } for (int k = 0; k < m; k++) { driver.get("http://live.com"); try { WebElement signout = driver.findElement(By.linkText("Sign out")); signout.click(); } catch (Exception e) { System.out.println("NO SUCH ELEMENT 'C_SIGNOUT'"); System.out.println("SIGNING IN"); } WebElement username = driver.findElement(By.id("i0116")); username.sendKeys(name); WebElement userpassword = driver.findElement(By.id("i0118")); userpassword.sendKeys(password); WebElement signin = driver.findElement(By.id("idSIButton9")); signin.click(); for (int j = 0; j < 41238; j++) { String word = sc.next(); list[j] = word; } for (int i = 0; i < n; i++) { Random rand = new Random(); driver.get("https://bing.com/"); WebElement query = driver.findElement(By.id("sb_form_q")); query.sendKeys(list[rand.nextInt(41238)]); WebElement go = driver.findElement(By.id("sbBtn")); go.click(); Thread.sleep(rand.nextInt(5000) + 5000); } } seleniumServer.stop(); }
From source file:botski.example.AddMeFastExample.java
License:Apache License
public void addMeFastLogin() throws Exception { driver.get("http://addmefast.com"); WebElement formEmail = driver.findElement(By.name("email")); formEmail.sendKeys(addmefastEmail);//from w w w . j a va2 s .co m WebElement formPassword = driver.findElement(By.name("password")); formPassword.sendKeys(addmefastPassword); WebElement formRemember = driver.findElement(By.name("remember")); formRemember.sendKeys(" "); WebElement formSubmit = driver.findElement(By.name("login_button")); formSubmit.click(); if ("http://addmefast.com/free_points.html".equals(driver.getCurrentUrl()) == false) { throw new Exception("Failed to login to addmefast.com as '" + addmefastEmail + "' using password '" + addmefastPassword + "', I ended up here '" + driver.getCurrentUrl() + "'"); } }
From source file:br.com.esign.logistics.test.selenium.page.HomePage.java
License:Open Source License
public void selectMap(String map) { WebElement mapAccordion = driver .findElement(By.xpath("//a[@class='accordion-toggle']/span[text()='" + map + "']")); waitForElement(mapAccordion);//w w w .j av a2 s.c o m mapAccordion.click(); }
From source file:br.edu.ifpb.praticas.testSystem.FilmeTest.java
@Test public void testCadastro() throws Exception { WebDriver driver = new FirefoxDriver(); WebElement element = driver.findElement(By.name("nome")); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. assertEquals("http://localhost:8085/SisFilme/index.xhtml", driver.getCurrentUrl()); Thread.sleep(2000L);// w ww .j ava2s . c o m element = driver.findElement(By.name("nome")); element.sendKeys("007 contra moscol"); element = driver.findElement(By.name("nome")); element.sendKeys("007 contra moscol"); element = driver.findElement(By.name("ano")); element.sendKeys("2014"); element = driver.findElement(By.name("genero")); element = driver.findElement(By.name("nota")); element.sendKeys("2"); element = driver.findElement(By.name("salvar")); Thread.sleep(2000L); element.click(); assertEquals("http://localhost:8085/SisFilme/gerenciamento.xhtml", driver.getCurrentUrl()); assertNotNull(element); // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { return d.getTitle().contains("NetBeans"); } }); //Close the browser driver.quit(); }