List of usage examples for org.openqa.selenium By className
public static By className(String className)
From source file:com.lazerycode.ebselen.handlers.LocatorHandler.java
License:Apache License
/** * Take a locator and work out what sort of By.xxx should be used * * @param locator - locator to evaluate//w w w. j a v a 2s. com * @return By - a By format that sky.sns.selenium 2 can utilise */ public By autoLocator(String locator) { switch (getLocatorType(locator)) { case XPATH: if (locator.startsWith("xpath=")) { locator = locator.split("=", 2)[1]; } return By.xpath(locator); case CSS_SELECTOR: if (locator.startsWith("css=")) { locator = locator.split("=", 2)[1]; } return By.cssSelector(locator); case ID: if (locator.startsWith("id=")) { locator = locator.split("=", 2)[1]; } return By.id(locator); case NAME: if (locator.startsWith("name=")) { locator = locator.split("=", 2)[1]; } return By.name(locator); case CLASS_NAME: if (locator.startsWith("class=")) { locator = locator.split("=", 2)[1]; } return By.className(locator); case TAG_NAME: if (locator.startsWith("tag=")) { locator = locator.split("=", 2)[1]; } return By.tagName(locator); case LINK_TEXT: if (locator.startsWith("link=")) { locator = locator.split("=", 2)[1]; } return By.linkText(locator); default: if (locator.startsWith("dom:name=")) { locator = locator.split("=", 2)[1]; return By.xpath("//form[@name='" + locator + "']"); } else if (locator.startsWith("dom:index=")) { locator = locator.split("=", 2)[1]; return By.xpath("(//form)[" + locator + "]"); } } return null; }
From source file:com.liferay.cucumber.selenium.WebDriverHelper.java
License:Open Source License
public static By getBy(String locator) { if (locator.startsWith("//")) { return By.xpath(locator); } else if (locator.startsWith("class=")) { locator = locator.substring(6);//from ww w.j a v a2 s. c o m return By.className(locator); } else if (locator.startsWith("css=")) { locator = locator.substring(4); return By.cssSelector(locator); } else if (locator.startsWith("link=")) { locator = locator.substring(5); return By.linkText(locator); } else if (locator.startsWith("name=")) { locator = locator.substring(5); return By.name(locator); } else if (locator.startsWith("tag=")) { locator = locator.substring(4); return By.tagName(locator); } else if (locator.startsWith("xpath=") || locator.startsWith("xPath=")) { locator = locator.substring(6); return By.xpath(locator); } else { return By.id(locator); } }
From source file:com.linagora.obm.ui.scenario.event.EventStepdefs.java
License:Open Source License
private boolean isDayOfMonthInPrintedWeek(DateTime dayOfMonth) { List<WebElement> dayElements = driver.findElements(By.className("dayLabel")); for (WebElement dayElement : dayElements) { WebElement href = dayElement.findElement(By.tagName("a")); if (href.getAttribute("onclick").contains(String.valueOf(dayOfMonth.getMillis() / 1000))) { return true; }/* w w w . ja v a 2 s. c o m*/ } return false; }
From source file:com.maoyan.pf.webcollector.spider.AttendrateCrawler.java
License:Open Source License
public static void main(String[] args) throws Exception { Executor executor = new Executor() { @Override/*from ww w .java2s .c o m*/ public void execute(CrawlDatum datum, CrawlDatums next) throws Exception { MongoClient mongoClient = new MongoClient("localhost", 27017); // ? // DBCollection dbCollection = mongoClient.getDB("maoyan_crawler").getCollection("rankings_am"); DB db = mongoClient.getDB("maoyan_crawler"); // ????? Set<String> colls = db.getCollectionNames(); for (String s : colls) { // Collection(?"") if (s.equals("attend_rate")) { db.getCollection(s).drop(); } } DBCollection dbCollection = db.getCollection("attend_rate"); HtmlUnitDriver driver = new HtmlUnitDriver(); driver.setJavascriptEnabled(false); driver.get(datum.getUrl()); // System.out.println(driver.getPageSource()); WebElement element = driver.findElementByCssSelector("div#seat_table"); List<WebElement> movie_name = element.findElements(By.className("c1 lineDot")); List<WebElement> boxoffice_rate = element.findElements(By.className("c2 red")); List<WebElement> visit_pershow = element.findElements(By.className("c3 gray")); WebElement cityarea = driver.findElementByCssSelector("span[class='today']"); System.out.println(cityarea.getText()); for (int i = 0; i < movie_name.size(); i++) { System.out.println(movie_name.get(i).getText()); System.out.println(boxoffice_rate.get(i).getText()); System.out.println(visit_pershow.get(i).getText()); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", cityarea.getText()).append("movie_name", movie_name.get(i).getText()) .append("boxoffice_rate", boxoffice_rate.get(i).getText()) .append("visit_pershow", visit_pershow.get(i).getText()); dbCollection.insert(dbObject); } mongoClient.close(); } }; //DBDBManager DBManager manager = new BerkeleyDBManager("maoyan"); //Crawler?DBManagerExecutor Crawler crawler = new Crawler(manager, executor); crawler.addSeed("http://pf.maoyan.com/attend/rate"); crawler.start(1); }
From source file:com.mastfrog.selenium.Utils.java
License:Open Source License
/** * Wait for a page element to be refreshed. Attempts to derive a * recipe for looking up the element from its attributes. May fail. * @param el The element//from w w w . j ava 2 s .co m */ public void waitForRefresh(final WebElement el) { By by = null; if (el.getAttribute("id") != null) { by = By.id(el.getAttribute("id")); } else if (el.getAttribute("name") != null) { by = By.name(el.getAttribute("name")); } else if (el.getAttribute("class") != null) { by = By.className(el.getAttribute("class")); } else if (el.getAttribute("style") != null) { by = By.cssSelector("style"); } else { throw new Error("No good way to look up " + el); } waitForRefresh(by); }
From source file:com.mediamelon.UserActions.java
void addAccount(WebDriver driver, List<String> formData) { //Verify if the user is logged in as Super User to create a new account. //If not, display message and return //Verify if the user is logged in String pageTitle = driver.getTitle(); Assert.assertEquals(pageTitle, "MediaMelon - Home"); String fullName = driver.findElement(By.xpath("//div[@class='row data']/div/div[1]/p[2]")).getText(); String role = driver.findElement(By.xpath("//div[@class='row data']/div/div[3]/p[2]")).getText(); if (fullName.equalsIgnoreCase("Super User") && role.equalsIgnoreCase("admin")) { System.out.println("List of Accounts is displayed"); //expand the settings menu option and click on Account Management List<WebElement> dropDownOptions = driver.findElements(By.className("dropdown-toggle")); dropDownOptions.get(0).click();/*from w ww. ja v a 2 s . c o m*/ WebElement accountManagement = driver.findElement(By.cssSelector(".dropdown-menu.dropdown-admin")); Assert.assertTrue(accountManagement.isDisplayed()); accountManagement.findElement(By.linkText("Account Management")).click(); Assert.assertEquals(driver.getTitle(), "List of Accounts"); WebElement accountsTable = driver.findElement(By.xpath("//div[@class='row well']/table")); Assert.assertTrue(accountsTable.isDisplayed()); WebElement addAccountBtn = driver.findElement(By.cssSelector(".btn.btn-primary")); System.out.println("Clicking on Add a new account button"); Assert.assertEquals(addAccountBtn.getText(), "Add a new Account"); addAccountBtn.click(); //Fill account add form WebElement accountForm = driver.findElement(By.tagName("form")); Assert.assertTrue(accountForm.isDisplayed()); System.out.println(accountForm.getAttribute("action")); accountForm.findElement(By.id("companyName")).sendKeys(formData.get(0)); accountForm.findElement(By.id("companyWebsite")).sendKeys(formData.get(1)); accountForm.findElement(By.id("adminName")).sendKeys(formData.get(2)); accountForm.findElement(By.id("adminEmail")).sendKeys(formData.get(3)); Select licenseType = new Select(driver.findElement(By.id("licenseType"))); licenseType.selectByVisibleText(formData.get(4)); Select services = new Select(driver.findElement(By.id("services"))); String requiredServices = formData.get(5); String multipleSel[] = formData.get(5).split(","); if (requiredServices.equalsIgnoreCase("All")) { services.selectByIndex(0); services.selectByIndex(1); services.selectByIndex(2); } else if (multipleSel.length > 1) { for (int i = 0; i < multipleSel.length; i++) services.selectByVisibleText(multipleSel[i]); } else services.selectByVisibleText(requiredServices); accountForm.findElement(By.id("companyName")).sendKeys(formData.get(5)); //submit the form System.out.println("Submitting the form"); accountForm.findElement(By.cssSelector("button[value='submit']")).click(); System.out.println("clicked on submit button"); accountsTable = driver.findElement(By.cssSelector("table.table-striped.table-hover.table-bordered")); Assert.assertTrue(accountsTable.isDisplayed()); System.out.println("form submitted sucessfully"); //Verify the presence of newly created account in the list of accounts System.out.println("Verifying if the newly created account is present in the list"); String tableData = accountsTable.getText(); System.out.println("Table Data: " + tableData); //findElement(By.xpath(".//*[@class='studyResultsId']/div/table/tbody/tr/td")).getText(); //Retrieving the data from the Td of table in to a string if (tableData.contains(formData.get(5))) { System.out.println("contains newly created account"); } else { System.out.println("does not contains newly created account"); } } else System.out.println("User not authorized to create an account"); }
From source file:com.mkl.websuites.command.OperationOnWebElement.java
License:Apache License
@Override protected void runCommandWithParameters() { by = null;//from w w w. ja va 2s . com if (parameterMap.keySet().contains("id")) { by = By.id(parameterMap.get("id")); } if (parameterMap.keySet().contains("css")) { by = By.cssSelector(parameterMap.get("css")); } if (parameterMap.keySet().contains("xpath")) { by = By.xpath(parameterMap.get("xpath")); } if (parameterMap.keySet().contains("className")) { by = By.className(parameterMap.get("className")); } if (parameterMap.keySet().contains("linkText")) { by = By.linkText(parameterMap.get("linkText")); } if (parameterMap.keySet().contains("partialLinkText")) { by = By.partialLinkText(parameterMap.get("partialLinkText")); } if (parameterMap.keySet().contains("name")) { by = By.name(parameterMap.get("name")); } if (parameterMap.keySet().contains("tagName")) { by = By.tagName(parameterMap.get("tagName")); } try { WebElement elem = browser.findElement(by); foundElement = elem; doOperationOnElement(elem); } catch (NoSuchElementException e) { fail("No element found for selecor " + by + " can be found on the page. " + "Selection parameters: " + parameterMap); } }
From source file:com.mkl.websuites.command.OperationOnWebElementTest.java
License:Apache License
@Test public void shouldRunForClassName(@Mocked final WebDriver browser) { runFor(browser, "className", "someClass", By.className("someClass")); }
From source file:com.moodle.testmanager.pageObjectModel.AssignmentSubmissionComments.java
License:GNU General Public License
/** * Clicks the comments link to display submission comments. *///from ww w. jav a 2 s . c o m public void clickLinkSubmissionComments() { WebElement link = driver.findElement(By.className("comment-link")); link.click(); }
From source file:com.moodle.testmanager.pageObjectModel.Databases.java
License:GNU General Public License
/** * Click 'Save Settings' button then wait for notify success to be returned. *///from w ww. j a v a2s. c om //TODO: revert back to original version and add a condition to handle no results returned public void clickSaveSettings() { WebElement saveSettingsButton = driver.findElement(By.xpath(".//input[@value='Save settings']")); saveSettingsButton.click(); (new WebDriverWait(driver, 60)).until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver d) { return d.findElement(By.className("notifysuccess")); } }); }