/*Admin Login*/ public void admin(String userAd, String passAd) { driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); siteAdmin.click(); userFieldAdmin.sendKeys(userAd); passFieldAdmin.sendKeys(passAd); loginButtonAdmin.click(); }
public void templateMng(String cbeez) { temManagerCP.click(); BeezTemp.click(); AdvanceBeez.click(); colorBeez.clear(); colorBeez.sendKeys(cbeez); saveCloseBeez.click(); }
/*Manage Categories*/ public void categoryManage(String titleCat, String aliasC, String textCat) { catmanagerButton.click(); newCategory.click(); titleFieldCat.sendKeys(titleCat); aliasCat.sendKeys(aliasC); toggleEdCat.click(); textFieldCategory.sendKeys(textCat); saveClose.click(); }
/*Edit Site Settings from HomePage*/ public void siteEdit(String siteNameText, String meta, String metaK) { siteSettings.click(); siteNameLabel.clear(); siteNameLabel.sendKeys(siteNameText); metaDescr.clear(); metaDescr.sendKeys(meta); metaKeys.clear(); metaKeys.sendKeys(metaK); saveSiteSettings.click(); }
/*Edit Template Settings from HomePage*/ public void edit(String colour, String bkColour, String frontTitle, String descrpt) { templateSettings.click(); temColour.clear(); temColour.sendKeys(colour); backColour.clear(); backColour.sendKeys(bkColour); titleFront.clear(); titleFront.sendKeys(frontTitle); description.clear(); description.sendKeys(descrpt); saveColour.click(); }
/*Edit Article from Control Panel*/ public void editArtCP(String labelArt, String datee) throws InterruptedException { articleMangerCP.click(); articleClickToEdit.click(); Thread.sleep(5000); toggleEdfromCP.click(); editLabelArt.clear(); editLabelArt.sendKeys(labelArt); publish.click(); FinishPub.clear(); FinishPub.sendKeys(datee); saveEditArt.click(); }
/* * (non-Javadoc) * * @see * qc.automation.framework.widget.IEditableField#setValue(java.lang.String) */ @Override public void setValue(Object value) throws WidgetException { try { if (value instanceof String) { boolean selected = false; List<WebElement> elements = findElements(); for (WebElement we : elements) { if (we.getAttribute("value").equals(value)) { we.click(); selected = true; break; } } if (!selected) throw new WidgetException("Could not find desired option to select", getLocator()); } else { throw new WidgetException( "Invalid type. 'value' must be a 'String' type of desired option to select", getLocator()); } } catch (Exception e) { throw new WidgetException("Error while selecting option on radio group", getLocator(), e); } }
protected void acceptDialog(WebElement frame, WebElement btn) { switchTo().frame(frame); btn.click(); delay(5000); setOpened(false); switchToMainWindow(); }
private boolean clickNext(WebDriver driver) { while (true) { boolean clicked = false; int iteration = 0; By by = By.className("show-next"); clickCloseModalIfAny(driver); for (WebElement el : driver.findElements(by)) { try { waitdriver.until(ExpectedConditions.elementToBeClickable(by)); el.click(); clicked = true; return true; } catch (Exception ex) { } } if (!clicked) { iteration++; continue; } if (!clicked && iteration > 3) { log.error("Element not clickable"); return false; } } }
@JavascriptEnabled @Test public void testCanClickOnSuckerFishMenuItem() throws Exception { if (!hasInputDevices()) { return; } driver.get(pages.javascriptPage); WebElement element = driver.findElement(By.id("menu1")); if (!TestUtilities.isNativeEventsEnabled(driver)) { System.out.println("Skipping hover test: needs native events"); return; } new Actions(driver).moveToElement(element).build().perform(); WebElement target = driver.findElement(By.id("item1")); assertTrue(target.isDisplayed()); target.click(); String text = driver.findElement(By.id("result")).getText(); assertTrue(text.contains("item 1")); }
@JavascriptEnabled @Test public void testSendingKeysToAFocusedElementShouldNotBlurThatElement() { assumeFalse(browserNeedsFocusOnThisOs(driver)); driver.get(pages.javascriptPage); WebElement element = driver.findElement(By.id("theworks")); element.click(); // Wait until focused boolean focused = false; WebElement result = driver.findElement(By.id("result")); for (int i = 0; i < 5; ++i) { String fired = result.getText(); if (fired.contains("focus")) { focused = true; break; } try { Thread.sleep(200); } catch (InterruptedException e) { throw new RuntimeException(e); } } if (!focused) { fail("Clicking on element didn't focus it in time - can't proceed so failing"); } element.sendKeys("a"); assertEventNotFired("blur"); }
// Q: what happens if I send text to alert? // A: ElementNotVisibleException in Firefox // A: in Chrome the text is sent @Test public void basicAlertHandlingKeysTest() { WebElement alertButton; WebElement alertResult; alertButton = driver.findElement(By.id("alertexamples")); alertButton.click(); String alertMessage = "I am an alert box!"; assertEquals(alertMessage, driver.switchTo().alert().getText()); if (Driver.currentDriver == Driver.BrowserName.FIREFOX) { try { driver.switchTo().alert().sendKeys("Hello keys Accept"); fail("expected a ElementNotVisibleException thrown"); } catch (ElementNotVisibleException e) { assertTrue("Expected to get an exception", true); } } if (Driver.currentDriver == Driver.BrowserName.GOOGLECHROME) { // chrome seems happy to send in text to an alert driver.switchTo().alert().sendKeys("Hello keys Accept"); } driver.switchTo().alert().accept(); }
@Test public void basicPromptConfirmHandlingDismissTest() { WebElement promptButton; WebElement promptResult; promptButton = driver.findElement(By.id("promptexample")); promptResult = driver.findElement(By.id("promptreturn")); assertEquals("pret", promptResult.getText()); promptButton.click(); String alertMessage = "I prompt you"; Alert promptAlert = driver.switchTo().alert(); if (Driver.currentDriver == Driver.BrowserName.IE) { // In IE the alert always returns "Script Prompt:" and not the // actual prompt text, so this line is just to alert me if the // functionality changes if (!promptAlert.getText().equals("Script Prompt:")) { throw new RuntimeException("IE now does not do Script Prompt"); } } else { // only check the alert prompt if not in IE assertEquals(alertMessage, promptAlert.getText()); } promptAlert.dismiss(); assertEquals("pret", promptResult.getText()); }
@Test public void basicPromptConfirmHandlingAcceptTest() { WebElement promptButton; WebElement promptResult; promptButton = driver.findElement(By.id("promptexample")); promptResult = driver.findElement(By.id("promptreturn")); assertEquals("pret", promptResult.getText()); promptButton.click(); String alertMessage = "I prompt you"; Alert promptAlert = driver.switchTo().alert(); if (Driver.currentDriver != Driver.BrowserName.IE) { // no point doing this in IE as we know it isn't the actual prompt assertEquals(alertMessage, promptAlert.getText()); } promptAlert.accept(); assertEquals("change me", promptResult.getText()); }
@JavascriptEnabled @Ignore(value = {HTMLUNIT, MARIONETTE}) @Test public void testShouldEmitOnClickEventsWhenSelectingElements() { driver.get(pages.javascriptPage); // Intentionally not looking up the select tag. See selenium r7937 for details. List<WebElement> allOptions = driver.findElements(By.xpath("//select[@id='selector2']//option")); WebElement foo = allOptions.get(0); WebElement bar = allOptions.get(1); foo.click(); assertThat(driver.findElement(By.id("result")).getText(), equalTo("foo")); bar.click(); assertThat(driver.findElement(By.id("result")).getText(), equalTo("bar")); }
/** * inchide dialogul cu promotiile * * @param driver */ private void clickCloseModalIfAny(WebDriver driver) { try { for (WebElement el : driver.findElements(By.className("box-content"))) { el.click(); } } catch (Exception ex) { // nothing } }
/** @param name */ private void selectItem(String name) { String expression = "//div[@id='ideQuickOutlineTree']//span[text()='" + name + "']"; WebElement element = driver.findElement(By.xpath(expression)); element.click(); element = driver.findElement(By.xpath(expression)); // element.click(); // element.click(); new Actions(driver).doubleClick(element).perform(); }
public void uncheck(String locator) { WebElement checkBox = driver.findElement(loc.autoLocator(locator)); if (!checkBox.getAttribute("type").toLowerCase().equals("checkbox")) { throw new InvalidElementTypeException("This elementLocator is not a checkbox!"); } if (checkBox.isSelected()) { checkBox.click(); } }
// This method takes to home page public void gotohomepage() { try { WebElement home = driver.findElement(By.linkText("Home")); home.click(); } catch (NoSuchElementException e) { logger.info("can't find home button on the page"); driver.switchTo().defaultContent(); gotohomepage(); } }
@Test public void testFindKioskFlow() throws Exception { driver.findElement(By.xpath("//a[contains(@href, '/fluffbox-rwx/kiosk/find')]")).click(); driver.findElement(By.id("searchCriteria")).sendKeys("Ft. Lauderdale"); driver.findElement(By.id("searchButton")).click(); WebElement walgreensInsideLink = waitForDynamicElement(By.linkText("Walgreens (Inside)")); walgreensInsideLink.click(); WebElement gMapInfoWindow = waitForDynamicElement(By.cssSelector("div.gmnoprint > div.gmnoprint > div > div")); assertThat(gMapInfoWindow.getText(), containsString("3895 W Broward Blvd")); WebElement winnDixieOutsideLink = waitForDynamicElement(By.linkText("Winn Dixie (Outside)")); winnDixieOutsideLink.click(); gMapInfoWindow = waitForDynamicElement(By.cssSelector("div.gmnoprint > div.gmnoprint > div > div")); assertThat(gMapInfoWindow.getText(), containsString("1531 N State Road 7")); }
@JavascriptEnabled @Test public void testShouldEmitClickEventWhenClickingOnATextInputElement() { driver.get(pages.javascriptPage); WebElement clicker = driver.findElement(By.id("clickField")); clicker.click(); wait.until(elementValueToEqual(clicker, "Clicked")); assertThat(clicker.getAttribute("value"), equalTo("Clicked")); }
@JavascriptEnabled @Test public void testShouldBeAbleToClickOnSubmitButtons() { driver.get(pages.javascriptPage); WebElement element = driver.findElement(By.id("submittingButton")); element.click(); waitForTitleChange("We Arrive Here"); assertThat(driver.getTitle(), is("We Arrive Here")); }
@JavascriptEnabled @Test public void testShouldBeAbleToSubmitFormsByCausingTheOnClickEventToFire() { driver.get(pages.javascriptPage); WebElement element = driver.findElement(By.id("jsSubmitButton")); element.click(); waitForTitleChange("We Arrive Here"); assertThat(driver.getTitle(), is("We Arrive Here")); }
@Ignore({HTMLUNIT, FIREFOX, SAFARI}) public void testOldPage() { driver.get(simpleTestPage); WebElement elem = driver.findElement(By.id("links")); driver.get(xhtmlTestPage); try { elem.click(); fail(); } catch (WebDriverException e) { // do nothing. this is what we expected. } }
@Test public void testUntitled2() throws Exception { driver.get(baseUrl + "php4dvd/"); WebElement userNameWebEdit = driver.findElement(By.id("username")); WebElement passwordWebEdit = driver.findElement(By.name("password")); WebElement subminButton = driver.findElement(By.name("submit")); userNameWebEdit.clear(); userNameWebEdit.sendKeys("admin"); passwordWebEdit.clear(); passwordWebEdit.sendKeys("admin"); subminButton.click(); }
@Test public void testOldPage() { driver.get(pages.simpleTestPage); WebElement elem = driver.findElement(By.id("links")); driver.get(pages.xhtmlTestPage); try { elem.click(); fail(); } catch (StaleElementReferenceException e) { // do nothing. this is what we expected. } }
@JavascriptEnabled @Test public void testIssue80ClickShouldGenerateClickEvent() { driver.get(pages.javascriptPage); WebElement element = driver.findElement(By.id("clickField")); assertEquals("Hello", element.getAttribute("value")); element.click(); String elementValue = wait.until(elementValueToEqual(element, "Clicked")); assertEquals("Clicked", elementValue); }
// Method for getting to reports page public void gotoreports(String domainName) { gotohomepage(); choosedomain(domainName); try { // click on On Demand Insight WebElement odi = (new WebDriverWait(driver, 10)) .until(ExpectedConditions.elementToBeClickable(By.xpath(odipath))); odi.click(); WebElement report = (new WebDriverWait(driver, 10)) .until(ExpectedConditions.elementToBeClickable(By.xpath(reportspath))); report.click(); WebElement cssr = (new WebDriverWait(driver, 10)) .until(ExpectedConditions.elementToBeClickable(By.xpath(cssrpath))); cssr.click(); } catch (Exception e) { System.out.print("trace: "); e.printStackTrace(); } }
public void optionalClick(final By locator) { WebElement we = null; try { we = driver.findElement(locator); we.click(); } catch (StaleElementReferenceException ser) { } catch (NoSuchElementException nse) { } catch (Exception e) { // staticlogger.info( e.getMessage() ); } }
@JavascriptEnabled @Ignore( value = {IE, HTMLUNIT}, reason = "IE: Only fires the onchange event when the checkbox loses the focus, " + "HtmlUnit: default mode is IE8 now") @Test public void testShouldEmitOnChangeEventsWhenChangingTheStateOfACheckbox() { driver.get(pages.javascriptPage); WebElement checkbox = driver.findElement(By.id("checkbox")); checkbox.click(); WebElement result = driver.findElement(By.id("result")); wait.until(elementTextToEqual(result, "checkbox thing")); }