List of usage examples for org.openqa.selenium By tagName
public static By tagName(String tagName)
From source file:beseenium.model.action.findElementsBy.FindElementsByTagName.java
License:Open Source License
/** * performs the find elements by tag name action * @param n the index of the element to find information on, i.e. if 3 results are found * the 0 will be the first element 1 the second and so on. will get an array out of bounds. * If you wish the action to return all of the results found then set n = -1. * @return String representation of the returnParam set in the ActionData object * passed into the constructor./*from w w w .j a v a 2s. co m*/ * @throws ActionDataException */ @Override public String execute(int n) throws ActionDataException { String searchParam = super.context.getInputParam(); WebDriver browser = super.context.getDriver(); List<WebElement> htmlElements = browser.findElements(By.tagName(searchParam)); super.context.setElement(htmlElements); return FormatOutput.formatFindElementOutput(htmlElements, n); }
From source file:bi.com.seleniumgrid.PhantomJsTest.java
License:Apache License
@Test public void test() { final DesiredCapabilities capabilities = new DesiredCapabilities(); // Configure our WebDriver to support JavaScript and be able to find the PhantomJS binary capabilities.setJavascriptEnabled(true); capabilities.setCapability("takesScreenshot", false); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_BINARY); final WebDriver driver = new PhantomJSDriver(capabilities); // Your test code here. For example: WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia pageTitle = driver.getTitle().trim(); Assert.assertEquals(pageTitle, "GoalQuest"); System.out.println("Page title is: " + driver.getTitle()); By searchInput = By.id("searchInput"); // search for "Software" wait.until(ExpectedConditions.presenceOfElementLocated(searchInput)); driver.findElement(searchInput).sendKeys("Software"); By searchButton = By.id("searchButton"); wait.until(ExpectedConditions.elementToBeClickable(searchButton)); driver.findElement(searchButton).click(); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text }
From source file:bi.meteorite.pages.SaikuTable.java
License:Apache License
public List<WebElement> firstRowElements() { return tableElement.findElement(By.tagName("tr")).findElements(By.xpath(".//td")); }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.primefaces.PrimeFacesEditor.java
License:Open Source License
public void sendKeys(CharSequence... keysToSend) { String[] id = getElementMap().locator(); String str;/*from www .ja va 2s . c o m*/ str = id[0].toString(); String value = charSequenceToString(keysToSend); WebDriver wd = super.getDriver(); WebElement frame = wd.findElement(By.xpath(str)); wd.switchTo().frame(frame); JavascriptExecutor js = null; if (wd instanceof JavascriptExecutor) { js = (JavascriptExecutor) wd; } WebElement editorBody = wd.findElement(By.cssSelector("body")); js.executeScript("arguments[0].innerHTML = ''", editorBody); wd.findElement(By.tagName("body")).sendKeys(value); wd.switchTo().defaultContent(); }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.primefaces.PrimeFacesEditor.java
License:Open Source License
/** * Funo que tenta preencher mais de uma vez o campo. Ela verifica se o * contedo enviado o mesmo que esta atualmente no campo. *///w ww .j a v a 2s . com public void sendKeysWithTries(CharSequence... keysToSend) { String[] id = getElementMap().locator(); String str; str = id[0].toString(); String value = charSequenceToString(keysToSend); WebDriver wd = super.getDriver(); WebElement frame = wd.findElement(By.xpath(str)); wd.switchTo().frame(frame); JavascriptExecutor js = null; if (wd instanceof JavascriptExecutor) { js = (JavascriptExecutor) wd; } WebElement editorBody = wd.findElement(By.cssSelector("body")); js.executeScript("arguments[0].innerHTML = ''", editorBody); wd.findElement(By.tagName("body")).sendKeys(value); wd.switchTo().defaultContent(); }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.primefaces.PrimeFacesEditor.java
License:Open Source License
@Override public String getText() { String[] id = getElementMap().locator(); String str;/* w ww. j av a2s. c o m*/ str = id[0].toString(); WebDriver wd = super.getDriver(); WebElement frame = wd.findElement(By.xpath(str)); wd.switchTo().frame(frame); String text = wd.findElement(By.tagName("body")).getText(); wd.switchTo().defaultContent(); return text; }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebAutoComplete.java
License:Open Source License
/** * Busca nas tags <li> ou <td> filhas de "element", um texto correspondente a * "value" na lista do autocomplete e seleciona-o * /*from www. j a v a 2s. co m*/ * @param WebElement element Elemento pai da lista de resultados do autocomplete * @param String value valor a ser procurado na lista */ protected void selectOnList(WebElement element, String value) { List<WebElement> elementValue = element.findElements(By.tagName("li")); if (elementValue.size() == 0) { elementValue = element.findElements(By.tagName("td")); } for (WebElement item : elementValue) { if (item.getText().equals(value)) { // Aguarda o segundo elemento ser clicvel try { item.click(); } catch (Throwable t) { waitElement(1); item.click(); } break; } } }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java
License:Open Source License
/** * Neste mtodo waitText estamos forando que seja verificado dentro do body * atravs de um loop controlado por ns e no pelo implicityWait do * Webdriver. Por isso zeramos o implicityWait e depois voltamos para o * valor padro das propriedades.//from w w w . j av a 2 s . com * * Mtodo que busca o texto visvel SOMENTE dentro do body do HTML. */ public void waitVisibleText(String text) { // Flag utilizada para o segundo lao boolean found = false; driver = (WebDriver) runner.getDriver(); frame = getSwitchDriver(driver); long startedTime = GregorianCalendar.getInstance().getTimeInMillis(); By by = By.tagName("body"); while (true) { try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); // Busca o texto no body List<WebElement> elementsFound = driver.findElements(by); if (elementsFound.size() > 0) { for (WebElement element : elementsFound) { if (element.getText().contains(text)) { found = true; break; } } } // Se no encontrar nada sem frames busca nos frames if (!found) { frame.bind(); for (int i = 0; i < frame.countFrames(); i++) { frame.switchNextFrame(); // Busca o texto no body elementsFound = driver.findElements(by); if (elementsFound.size() > 0) { for (WebElement element : elementsFound) { if (element.getText().contains(text)) { found = true; break; } } } } driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS); } } catch (BehaveException be) { throw be; } catch (StaleElementReferenceException ex) { // Ignore this exception } catch (NoSuchFrameException ex) { throw new BehaveException(message.getString("exception-no-such-frame", frame.currentFrame(), ex)); } catch (Exception e) { throw new BehaveException(message.getString("exception-unexpected", e.getMessage()), e); } finally { driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS); } if (found) { break; } waitThreadSleep(BehaveConfig.getRunner_ScreenMinWait()); if ((GregorianCalendar.getInstance().getTimeInMillis() - startedTime) > BehaveConfig .getRunner_ScreenMaxWait()) { Assert.fail(message.getString("message-text-not-found", text)); } } }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java
License:Open Source License
/** * Neste mtodo waitText estamos forando que seja verificado dentro do body * atravs de um loop controlado por ns e no pelo implicityWait do * Webdriver. Por isso zeramos o implicityWait e depois voltamos para o * valor padro das propriedades./*from w w w . jav a2 s. c om*/ * * Mtodo que busca o texto visvel SOMENTE dentro do body do HTML. */ public void waitNotVisibleText(String text) { // Flag utilizada para o segundo lao boolean found = false; driver = (WebDriver) runner.getDriver(); frame = getSwitchDriver(driver); long startedTime = GregorianCalendar.getInstance().getTimeInMillis(); By by = By.tagName("body"); while (true) { try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); // Busca o texto no body List<WebElement> elementsFound = driver.findElements(by); if (elementsFound.size() > 0) { for (WebElement element : elementsFound) { if (element.getText().contains(text)) { found = true; break; } } } // Se no encontrar nada sem frames busca nos frames if (!found) { frame.bind(); for (int i = 0; i < frame.countFrames(); i++) { frame.switchNextFrame(); // Busca o texto no body elementsFound = driver.findElements(by); if (elementsFound.size() > 0) { for (WebElement element : elementsFound) { if (element.getText().contains(text)) { found = true; break; } } } } driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS); } } catch (BehaveException be) { throw be; } catch (StaleElementReferenceException ex) { // Ignore this exception } catch (NoSuchFrameException ex) { throw new BehaveException(message.getString("exception-no-such-frame", frame.currentFrame(), ex)); } catch (Exception e) { throw new BehaveException(message.getString("exception-unexpected", e.getMessage()), e); } finally { driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS); } if (!found) { break; } waitThreadSleep(BehaveConfig.getRunner_ScreenMinWait()); if ((GregorianCalendar.getInstance().getTimeInMillis() - startedTime) > BehaveConfig .getRunner_ScreenMaxWait()) { Assert.fail(message.getString("message-text-found", text)); } } }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java
License:Open Source License
/** * Retira o foco do campo. O comportamento padro para isso selecionar o * <body>/*ww w . java 2 s . co m*/ */ public void blur() { driver = (WebDriver) runner.getDriver(); driver.findElement(By.tagName("body")).click(); }