List of usage examples for org.openqa.selenium By cssSelector
public static By cssSelector(String cssSelector)
From source file:com.axatrikx.webdriver.ElementHelper.java
License:Apache License
private By parseLocator(String locator) { String locValue;/*from w ww .j a va 2 s . co 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.blogspot.jadecalyx.webtools.jcWebPage.java
public List<WebElement> GetWebList(String objectHandle) { Stack<jcPageObjectSet> lookupInfo = _pageObjectHelper.GetLookupDetails(objectHandle); WebElement el = extractElement(null, lookupInfo); List<WebElement> returnList = new ArrayList<WebElement>(); List<WebElement> elements = el.findElements(By.cssSelector("li")); for (WebElement e : elements) { returnList.add(e);/* ww w . j a v a 2 s .c o m*/ } return returnList; }
From source file:com.blogspot.jadecalyx.webtools.jcWebPage.java
private WebElement extractElement(WebElement currElement, Stack<jcPageObjectSet> cssStack) { if (cssStack.empty()) { return currElement; }//from w ww.j a v a 2s.com jcPageObjectSet currSet = cssStack.pop(); List<WebElement> wel; if (currElement == null) { wel = _driver.findElements(By.cssSelector(currSet.GetDetails())); } else { wel = currElement.findElements(By.cssSelector(currSet.GetDetails())); } if (!wel.isEmpty()) { return extractElement(wel.get(0), cssStack); } else { return null; } }
From source file:com.bna.ezrxlookup.ui.web.EZRxBusinessTests.java
License:Apache License
@Test public void testEZRxLookupResultPageNoNegativeNoRecalls() throws Exception { try {/*from ww w .ja va 2 s .com*/ driver.get(baseUrl + "/EZRxLookup/"); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear(); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys(""); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear(); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("51439-007-02"); driver.findElement(By.id("j_idt5:j_idt18:search")).click(); for (int second = 0;; second++) { if (second >= 10) fail("timeout"); try { if (isElementPresent(By.cssSelector("label"))) break; } catch (Exception e) { } Thread.sleep(1000); } Thread.sleep(3000); assertEquals("ACNE CLEARNING TREATMENT FACE", driver.findElement(By.id("j_idt5:j_idt19:cmdBName")).getText()); WebElement element = driver.findElement(By.id("j_idt5:j_idt19:j_idt28")); String path = element.getAttribute("src"); assert (path.contains("green")); } catch (Error e) { verificationErrors.append(e); } }
From source file:com.bna.ezrxlookup.ui.web.EZRxBusinessTests.java
License:Apache License
@Test public void testEZRxLookupResultPageNegativeEventsNoRecalls() throws Exception { try {/* w ww . j a va 2 s . c om*/ driver.get(baseUrl + "/EZRxLookup/"); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear(); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys(""); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear(); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("53746-078-01"); driver.findElement(By.id("j_idt5:j_idt18:search")).click(); for (int second = 0;; second++) { if (second >= 10) fail("timeout"); try { if (isElementPresent(By.cssSelector("label"))) break; } catch (Exception e) { } Thread.sleep(1000); } Thread.sleep(3000); assertEquals("ESTERIFIED ESTROGENS AND METHYLTESTOSTERONE", driver.findElement(By.id("j_idt5:j_idt19:cmdBName")).getText()); WebElement element = driver.findElement(By.id("j_idt5:j_idt19:j_idt28")); String path = element.getAttribute("src"); assert (path.contains("yellow")); } catch (Error e) { verificationErrors.append(e); } }
From source file:com.bna.ezrxlookup.ui.web.EZRxBusinessTests.java
License:Apache License
@Test public void testEZRxLookupResultPageRecallsFound() throws Exception { try {//from w w w . ja v a2 s . c o m driver.get(baseUrl + "/EZRxLookup/"); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear(); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys(""); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).clear(); driver.findElement(By.id("j_idt5:j_idt18:drugName_input")).sendKeys("43598-209-53"); driver.findElement(By.id("j_idt5:j_idt18:search")).click(); for (int second = 0;; second++) { if (second >= 10) fail("timeout"); try { if (isElementPresent(By.cssSelector("label"))) break; } catch (Exception e) { } Thread.sleep(1000); } Thread.sleep(3000); assertEquals("AMOXICILLIN", driver.findElement(By.id("j_idt5:j_idt19:cmdBName")).getText()); WebElement element = driver.findElement(By.id("j_idt5:j_idt19:j_idt28")); String path = element.getAttribute("src"); assert (path.contains("red")); } catch (Error e) { verificationErrors.append(e); } }
From source file:com.cengage.mindtap.keywords.DashBoardPageActions.java
private void clickOnUserMenuLink() { try {//from w w w. ja v a2 s . c o m driver.switchTo().defaultContent(); driver.findElement(By.cssSelector(".user-menu-link.tb_item")); ((JavascriptExecutor) driver) .executeScript("document.getElementsByClassName('user-menu')[0].style.display = 'block';"); } catch (Exception e) { ReportMsg.info("Logout dropdown list not displayed"); } }
From source file:com.cengage.mindtap.keywords.GoogleDriveAppPageActions.java
public boolean addGoogleDocApp(String gmailID, String password) { try {/*from w ww . ja v a 2 s .c o m*/ acceptAlertWindow(); driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); } catch (Exception e) { } String categoryHeader = driver.findElement(By.id("title")).getText(); if (categoryHeader.contains("Google Drive")) { Reporter.log("Google Docs Icon is already displayed"); } else { element("googleDriveIcon").click(); try { acceptAlertWindow(); driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); } catch (Exception e) { } } switchToAppIFrame(); try { driver.findElement(By.cssSelector(".addnewAccount")); signInAndCheckAccessForAppDock(gmailID, password); checkAndUncheckShowAllContent(); driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); } catch (Exception e) { deselectFrame(); } return true; }
From source file:com.cengage.mindtap.keywords.GoogleDriveAppPageActions.java
/** * Adds the distinct google doc activity. * * @param title the title/*from ww w. j a va 2 s. c om*/ * @param email the email * @param password the password * @return true, if successful */ public void addDistinctGoogleDocActivity(String title, String email, String password) { //performClickOnAddActivityIcon(); clickOnMyContentAndGoogleDocFromMenu(); try { handleAlert(); acceptAlertWindow(); } catch (Exception e) { } switchToActivityIFrame(); try { resetImplicitTimeout(2); driver.findElement(By.cssSelector(".addnewAccount")); signInAndCheckAccessForActivity(email, password); driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); } catch (Exception e) { } finally { resetImplicitTimeout(AJAX_WAIT); deselectFrame(); //driver.switchTo().frame(driver.findElement(By.id("distinct_activity_create_frame")).getAttribute("name")) switchToActivityIFrame(); selectShowFilesCheckbox(); /** Commenting as per NG-16026**/ verifyFilteringOptions(); verifySortingOperations(); addGDocActivity(); element("continue_btn").click(); element("saveDistinctActivity").click(); deselectFrame(); //element("saveActivity").click(); saveDistinctGoogleDocActivity(title); } }
From source file:com.cengage.mindtap.keywords.GoogleDriveAppPageActions.java
/** * Adds the distinct google inline doc activity. * * @param title the title// ww w . j ava 2s. c o m * @param email the email * @param password the password */ public void addDistinctGoogleInlineDriveActivity(String title, String email, String password) { //performClickOnAddActivityIcon(); clickOnMyContentAndGoogleDocFromMenu(); try { handleAlert(); acceptAlertWindow(); } catch (Exception e) { } switchToActivityIFrame(); try { resetImplicitTimeout(2); driver.findElement(By.cssSelector(".addnewAccount")); signInAndCheckAccessForActivity(email, password); driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); } catch (Exception e) { } finally { resetImplicitTimeout(AJAX_WAIT); deselectFrame(); //driver.switchTo().frame(driver.findElement(By.id("distinct_activity_create_frame")).getAttribute("name")) switchToActivityIFrame(); selectShowFilesCheckbox(); /** Commenting as per NG-16026**/ verifyFilteringOptions(); verifySortingOperations(); addGDocActivity(); element("continue_btn").click(); element("inlineTitle").sendKeys(title); element("saveDistinctActivity").click(); wait.hardWait(10); deselectFrame(); } }