List of usage examples for org.openqa.selenium By className
public static By className(String className)
From source file:com.axatrikx.webdriver.ElementHelper.java
License:Apache License
private By parseLocator(String locator) { String locValue;/*from w w w .j a v a 2s. c o m*/ By byElement = null; if (locator.toLowerCase().startsWith("id=")) { locValue = locator.substring(3); byElement = By.id(locValue); } else if (locator.toLowerCase().startsWith("name=")) { locValue = locator.substring(5); byElement = By.name(locValue); } else if (locator.toLowerCase().startsWith("class=")) { locValue = locator.substring(6); byElement = By.className(locValue); } else if (locator.toLowerCase().startsWith("css=")) { locValue = locator.substring(4); byElement = By.cssSelector(locValue); } else if (locator.toLowerCase().startsWith("xpath=")) { locValue = locator.substring(6); byElement = By.xpath(locValue); } else if (locator.toLowerCase().startsWith("classname=")) { locValue = locator.substring(10); byElement = By.className(locValue); } else if (locator.toLowerCase().startsWith("tagname=")) { locValue = locator.substring(8); byElement = By.tagName(locValue); } else if (locator.toLowerCase().startsWith("link=")) { locValue = locator.substring(5); byElement = By.linkText(locValue); } else if (locator.toLowerCase().startsWith("partiallinktext=")) { locValue = locator.substring(16); byElement = By.partialLinkText(locValue); } else { // set default to id byElement = By.id(locator); } return byElement; }
From source file:com.cengage.mindtap.keywords.searchPageAction.java
/** * Select search term./* ww w . j av a 2 s . c om*/ * * @param searchTerm the search term */ public void selectSearchTerm(String searchTerm) { waitForElementPresent("suggestion_box"); searchTerm = searchTerm.toUpperCase(); boolean flag = true; while (flag) { List<WebElement> suggestion_list = driver.findElements(By.xpath("//div[@class='hits']//ul/li")); for (WebElement searchItem : suggestion_list) { try { searchItem.findElement(By.xpath(".//div[@class='hit-highlights']")).click(); System.out.println(searchItem.getText() + "Test Passed"); flag = false; break; } catch (Exception e) { continue; } } //***** Click on Show More button if text not found ******** if (flag = true) { System.out.println("Test Failing"); try { //To avoid stale element exception driver.findElement(By.className("showMore")); element("showMore_btn").click(); } catch (Exception e) { flag = false; } } } //******* Clear the search term from search box ************* // clearSearchResult(); //******* Hide the dock app ************* //clickOnHideApp(); }
From source file:com.chtr.tmoauto.webui.CommonFunctions.java
License:Open Source License
/** * /*w ww .ja v a 2 s. com*/ * @param locator * @return */ public By getSelector(String locator) { String[] prefix = locator.split("=", 2); if (prefix[0].equals("css")) { return By.cssSelector(prefix[1]); } else if (prefix[0].equals("id")) { return By.id(prefix[1]); } else if (prefix[0].equals("class")) { return By.className(prefix[1]); } else if (prefix[0].equals("xpath")) { return By.xpath(prefix[1]); } else if (prefix[0].equals("link")) { return By.linkText(prefix[1]); } else if (prefix[0].equals("name")) { return By.name(prefix[1]); } else if (locator.startsWith("//")) { return By.xpath(locator); } else if (locator.startsWith(".//")) { return By.xpath(locator); } else { return By.id(locator); } }
From source file:com.cloudbees.workflow.ui.view.WorkflowStageViewActionTest.java
License:Open Source License
@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver") @Test/*from w w w. j av a 2 s.co m*/ public void test() throws Exception { WebDriver webdriver = getWebDriver(); WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job"); job.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build'); " + " sh ('echo Building'); " + " stage ('Test'); " + " sh ('echo Testing'); " + " stage ('Deploy'); " + " sh ('echo Deploying'); " + "}")); QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0); jenkinsRule.assertBuildStatusSuccess(build); String jobUrl = getItemUrl(jenkinsRule.jenkins, job); webdriver.get(jobUrl); // System.out.println(webdriver.getPageSource()); // Make sure the jobsTable is rendered in the page WebElement jobsTable = webdriver.findElement(By.className("jobsTable")); Assert.assertNotNull(jobsTable); // Check the totals are rendered // List<WebElement> stageWrappers = jobsTable.findElements(By.cssSelector(".totals .stage-wrapper")); // Assert.assertEquals(3, stageWrappers.size()); // Should have just one job List<WebElement> jobs = jobsTable.findElements(By.cssSelector(".job")); Assert.assertEquals(1, jobs.size()); // That job should have 3 stages List<WebElement> jobStages = jobs.get(0).findElements(By.cssSelector(".stage-wrapper")); Assert.assertEquals(3, jobStages.size()); }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Method to set date in a date picker//from w ww . j a va 2s .c o m * @author Ruth Chirinos * @param driver the WebDriver * @param xpathDatePicker the xpath of the datePicker * @param vehicleSelectionPage * year - the year minus 1900. * month - the month between 0-11. * date - the day of the month between 1-31. * @throws InterruptedException * @throws ParseException */ public static boolean setDateInDatePicker(WebDriver driver, String xpathDatePicker, Date dateRequested) throws InterruptedException, ParseException { Calendar dateRequestedCalendar = DateUtil.getCalendarForDate(dateRequested); LogUtil.log("Date for changing is > " + DateUtil.format(dateRequestedCalendar, DateUtil.DATE_MONTH_ABBREVIATION), LogLevel.LOW); boolean processOk = false; String dateSelectedString = ""; Date dateSelected = null; SimpleDateFormat simpleFormat = new SimpleDateFormat(DateUtil.DATE_MONTH_YEAR_FMT); WebElement datePicker = driver.findElement(By.xpath(xpathDatePicker)); datePicker.click(); WebElement monthYearElement = driver .findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); WebElement daySelected = driver.findElement(By.xpath("//*[contains(@class, 'x-datepicker-selected')]/a")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); WebElement pickerPrevEl = driver.findElement( By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-prev')]")); WebElement pickerNextEl = driver.findElement( By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-next')]")); //Choosing the year while (dateRequested.getYear() < dateSelected.getYear()) { pickerPrevEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } while (dateRequested.getYear() > dateSelected.getYear()) { pickerNextEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } //Choosing the months while (dateRequested.getMonth() < dateSelected.getMonth()) { pickerPrevEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } while (dateRequested.getMonth() > dateSelected.getMonth()) { pickerNextEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } //Choosing the day WebElement dateWidget = driver.findElement(By.className("x-datepicker-inner")); List<WebElement> columns = dateWidget.findElements(By.tagName("td")); int aux = 0; for (WebElement cell : columns) { if (cell.getText().equals(dateRequested.getDate() + "")) { processOk = cell.getAttribute("class").contains("x-datepicker-active"); if (processOk) { cell.findElement(By.tagName("a")).click(); ; LogUtil.log("The date was selected.", LogLevel.LOW); aux = 1; break; } } } if (aux == 0) { LogUtil.log("The date selected is not enabled.", LogLevel.LOW); } return processOk; }
From source file:com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.PathBrowser.java
License:Apache License
/** * Sets path in path browser.// w ww . j a va 2 s . co m * * @param value string path value. */ @Override public void setValue(Object value) { if (contains(currentScope.getAttribute(HtmlTags.Attributes.CLASS), TEXT_FIELD_CLASS)) { currentScope.clear(); currentScope.sendKeys(String.valueOf(value)); } else { input.clear(); input.sendKeys(String.valueOf(value)); } bobcatWait.until(ExpectedConditions.visibilityOfElementLocated( By.cssSelector(".foundation-picker-buttonlist.coral3-Overlay.is-open"))); currentScope.findElement(By.className("coral-Form-fieldlabel")).click(); }
From source file:com.cognifide.qa.bb.aem.core.sidepanel.internal.ComponentTreeLocatorHelper.java
License:Apache License
private static WebElement setComponent(WebElement component, String container) { List<WebElement> elements = component.findElements(By.className("coral3-Tree-item--drilldown")); if (!elements.isEmpty()) { return elements.get(calculateElementNumber(container)); }//from w w w . ja va2 s . c o m return component; }
From source file:com.cognifide.qa.bb.aem.core.sidepanel.internal.SidePanelTabBarImpl.java
License:Apache License
@Override public void switchTab(String tab) { bobcatWait.until(elementIsReady(currentScope.findElement(By.className(tab)))).click(); }
From source file:com.cognifide.qa.bb.aem.core.siteadmin.internal.SiteToolbarImpl.java
License:Apache License
@Override public void createPage(String template, String title, String name) { Actions actions = new Actions(webDriver); actions.pause(2000).perform();/* w ww .ja v a 2 s . c o m*/ createButton.click(); currentScope.findElement(By.className("cq-siteadmin-admin-create" + StringUtils.lowerCase("page"))).click(); createPageWizard.selectTemplate(template).provideTitle(title).provideName(name).submit(); }
From source file:com.cognifide.qa.bb.aem.dialog.classic.field.AemRichText.java
License:Apache License
private boolean isRichtextDisabled() { return currentScope.findElement(By.className(BUTTON_CLASS_NAME)).getAttribute(CLASS_ATTRIBUTE) .contains(DISABLED_CLASS_NAME); }