List of usage examples for org.openqa.selenium By cssSelector
public static By cssSelector(String cssSelector)
From source file:com.cengage.mindtap.keywords.GradeBookAppPageAction.java
public void verifyStudentScore(String name) { waitTOSync();//from w ww. j a v a 2s. c om element("back_btn").click(); waitTOSync(); String score1 = element("student_score").getText().toString(); waitTOSync(); element("SelectStudent", name).click(); WebElement score = driver.findElement(By.cssSelector("svg .class_average")); // String score2 = element("student_score").getText().toString(); String score2 = score.getText().toString(); System.out.println("score2:" + score2); Assert.assertTrue(score1.contentEquals(score2), "Score not maching for particular student"); }
From source file:com.cengage.mindtap.keywords.MasterPageActions.java
/** * Search book on masters page./* w w w. j a v a2 s.com*/ * * @param searchTerm the search term */ public void searchBookOnMastersPage(String searchTerm) { //waitForElementDisplayed(By.cssSelector(".listContainer")); //To avoid stale element exception driver.findElements(By.cssSelector(".listContainer")); element("neXtBookSearch_inputBox").click(); element("neXtBookSearchInputBoxActivated").click(); element("neXtBookSearchInputBoxActivated").clear(); element("neXtBookSearchInputBoxActivated").sendKeys(searchTerm); waitTOSync(); waitForSpinnerToDisappear(); element("notPublished_btn").click(); try { resetImplicitTimeout(1); waitForSpinnerToDisappear(); resetImplicitTimeout(AJAX_WAIT); } catch (Exception e) { } }
From source file:com.cengage.mtx.keywords.MTXActivityPageAction.java
public void selectDropDownAnswers() { switchToDefaultContent();//from w w w . java2s . c o m switchToFrame(driver.findElement(By.id("97_NB_Main_IFrame"))); wait.hardWait(5); switchToFrame(driver.findElement(By.cssSelector("iframe[id*='easyXDM']"))); // selectProvidedTextFromDropDown(element("selectAnsDropDownOne"),"macroscopic"); // selectProvidedTextFromDropDown(element("selectAnsDropDownTwo"),"macroscopic"); // selectProvidedTextFromDropDown(element("selectAnsDropDownThree"),"macroscopic"); wait.hardWait(5); // Select(driver.findElement(element("selectAnsDropDownOne"))); // Select(driver.findElement(By.id("selectAnsDropDownTwo"))); // Select(driver.findElement(By.id("SelectID_One"))); Select selectByValue = new Select(element("selectAnsDropDownOne")); selectByValue.selectByVisibleText("macroscopic"); wait.hardWait(5); selectByValue = new Select(element("selectAnsDropDownTwo")); selectByValue.selectByVisibleText("macroscopic"); wait.hardWait(5); selectByValue = new Select(element("selectAnsDropDownThree")); selectByValue.selectByVisibleText("macroscopic"); // Select selectByValue = new Select(element("selectAnsDropDownTwo")); // selectByValue.selectByValue("macroscopic"); // // Select selectByValue = new Select(element("selectAnsDropDownThree")); // selectByValue.selectByValue("macroscopic"); }
From source file:com.chtr.tmoauto.webui.CommonFunctions.java
License:Open Source License
/** * //w w w .j a v a2 s.c o m * @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.AbstractPhantomJSTest.java
License:Open Source License
protected void moveMouseOffElement(WebDriver webdriver) { Actions actions = new Actions(webdriver); actions.moveToElement(webdriver.findElement(By.cssSelector("html"))).build().perform(); }
From source file:com.cloudbees.workflow.ui.AbstractPhantomJSTest.java
License:Open Source License
protected List<WebElement> waitForElementsAdded(WebElement inElement, String cssSelector) { List<WebElement> elements = Collections.EMPTY_LIST; long start = System.currentTimeMillis(); while (elements.isEmpty() && System.currentTimeMillis() < (start + 20000)) { elements = inElement.findElements(By.cssSelector(cssSelector)); }/*from ww w .j ava 2 s.co m*/ if (elements.isEmpty()) { Assert.fail("Timed out waiting on elements matching CSS selector '" + cssSelector + "' to appear on the page."); } return elements; }
From source file:com.cloudbees.workflow.ui.AbstractPhantomJSTest.java
License:Open Source License
protected List<WebElement> waitForElementsAdded(WebDriver webdriver, String cssSelector) { return waitForElementsAdded(webdriver.findElement(By.cssSelector("html")), cssSelector); }
From source file:com.cloudbees.workflow.ui.AbstractPhantomJSTest.java
License:Open Source License
protected void waitForElementsRemoved(WebElement inElement, String cssSelector) { List<WebElement> elements = inElement.findElements(By.cssSelector(cssSelector)); long start = System.currentTimeMillis(); while (!elements.isEmpty() && System.currentTimeMillis() < (start + 20000)) { elements = inElement.findElements(By.cssSelector(cssSelector)); }/*from w w w. j av a 2 s .c om*/ if (!elements.isEmpty()) { Assert.fail("Timed out waiting on elements matching CSS selector '" + cssSelector + "' to be removed from the page."); } }
From source file:com.cloudbees.workflow.ui.AbstractPhantomJSTest.java
License:Open Source License
protected void waitForElementsRemoved(WebDriver webdriver, String cssSelector) { waitForElementsRemoved(webdriver.findElement(By.cssSelector("html")), cssSelector); }
From source file:com.cloudbees.workflow.ui.view.BuildArtifactsTest.java
License:Open Source License
@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver") @Test/*from w w w. jav 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 ('Archiving'); " + " sh('mkdir targs && echo hello > targs/hello1.txt && echo hello > targs/hello2.txt'); " + " archive(includes: 'targs/*.txt'); " + "}")); QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0); jenkinsRule.assertBuildStatusSuccess(build); String jobUrl = getItemUrl(jenkinsRule.jenkins, job); webdriver.get(jobUrl); // Look for the build artifacts popup button... WebElement buildArtifactsPopupBtn = webdriver.findElement(By.cssSelector(".build-artifacts-popup")); Assert.assertNotNull(buildArtifactsPopupBtn); // Move over the button to load the popover... moveMouseToElement(webdriver, buildArtifactsPopupBtn); // Look for and test the popover content... List<WebElement> buildArtifactsPopover = waitForElementsAdded(webdriver, ".cbwf-build-artifacts"); Assert.assertEquals(1, buildArtifactsPopover.size()); WebElement popover = buildArtifactsPopover.get(0); List<WebElement> artifacts = waitForElementsAdded(popover, ".artifact"); Assert.assertEquals(2, artifacts.size()); // TODO: Something strange here with selenium. // Can't seem to get the text of that element even though it is there if you sout the whole page. // isDisplayed on those anchor elements returns false for some reason, even though the parent elements // are "displayed". // Assert.assertEquals("hello1.txt", artifacts.get(0).findElement(By.cssSelector(".name")).getText()); // Assert.assertEquals("hello2.txt", artifacts.get(1).findElement(By.cssSelector(".name")).getText()); // Make sure it goes away once we move off the popover... moveMouseOffElement(webdriver); waitForElementsRemoved(webdriver, ".cbwf-build-artifacts"); }