List of usage examples for org.openqa.selenium.remote RemoteWebDriver findElements
@Override
public List<WebElement> findElements(By by)
From source file:com.watchrabbit.crawler.auth.service.AuthServiceImpl.java
License:Apache License
private WebElement locateLoginForm(RemoteWebDriver driver) { for (WebElement form : driver.findElements(By.xpath("//form"))) { LOGGER.debug("Looking to form with action {}", form.getAttribute("action")); List<WebElement> inputs = form.findElements(By.xpath(".//input")).stream() .filter(input -> isLoginInput(input) || isPasswordInput(input)) .filter(input -> input.isDisplayed()).collect(toList()); if (inputs.size() == 2) { return form; }//from w w w.j a v a 2 s.co m } return null; }
From source file:com.watchrabbit.crawler.executor.service.CrawlExecutorServiceImpl.java
License:Apache License
private List<String> collectLinks(RemoteWebDriver driver) { return driver.findElements(By.xpath("//a")).stream().filter(element -> element.isDisplayed()) .map(link -> link.getAttribute("href")).filter(link -> link != null) .filter(link -> link.startsWith("http")).distinct().collect(toList()); }
From source file:com.watchrabbit.crawler.executor.service.CrawlExecutorServiceImpl.java
License:Apache License
private Optional<SearchForm> findSearchInput(RemoteWebDriver driver) { for (WebElement form : driver.findElements(By.xpath("//form"))) { LOGGER.debug("Looking to form with action {}", form.getAttribute("action")); List<WebElement> inputs = form.findElements(By.xpath(".//input")).stream() .filter(input -> input.getAttribute("type").equals("text") || input.getAttribute("type").equals("search")) .filter(input -> input.isDisplayed()).collect(toList()); List<WebElement> passwords = form.findElements(By.xpath(".//input")).stream() .filter(input -> input.getAttribute("type").equals("password")) .filter(input -> input.isDisplayed()).collect(toList()); if (inputs.size() == 1 && passwords.isEmpty()) { List<WebElement> submit = form.findElements(By.xpath(".//button[@type='submit']")); if (submit.isEmpty()) { submit = form.findElements(By.xpath(".//input[@type='submit']")); }//from w w w.j a v a2s.c o m if (!submit.isEmpty()) { return Optional.of(new SearchForm(inputs.get(0), submit.get(0))); } } } LOGGER.error("Cannot find form in gateway page"); return Optional.<SearchForm>empty(); }
From source file:com.watchrabbit.scanner.supervisor.service.FormAnalyzerServiceIT.java
License:Apache License
@Test public void shouldAnalyzeForm() throws InvalidFormStructureException { RemoteWebDriver driver = firefoxFactory.produceDriver(); try {//from w w w .jav a 2s . c o m driver.get("https://reg.ebay.pl/reg/FullReg"); List<WebElement> findElements = driver.findElements(By.xpath("//form")); Form prepareStructure = formAnalyzeService.prepareStructure(findElements.get(0)); formDataGeneratorStrategy.generateFormData(prepareStructure, asList("Test")); assertThat(prepareStructure.getFields()).isNotEmpty(); } finally { firefoxFactory.returnWebDriver(driver); } }
From source file:com.watchrabbit.scanner.supervisor.service.FormAnalyzerServiceIT.java
License:Apache License
@Test public void shouldPerformAttacks() throws InvalidFormStructureException, URISyntaxException { RemoteWebDriver driver = firefoxFactory.produceDriver(); try {/*from w ww .java 2 s .co m*/ driver.get("https://ssl.allegro.pl/fnd/registration/"); List<WebElement> findElements = driver.findElements(By.xpath("//form")); Form prepareStructure = formAnalyzeService.prepareStructure(findElements.get(0)); formDataGeneratorStrategy.generateFormData(prepareStructure, asList("Test")); AttackData prepareData = attackGeneratorService.prepareData("adsa1232", prepareStructure); AttackResult attackResult = attackerService.performAttack("https://ssl.allegro.pl/fnd/registration/", driver, prepareData); resultProcessingStrategy.onTestComplete("adsa1232", "https://ssl.allegro.pl/fnd/registration/", (attackResult)); assertThat(prepareStructure.getFields()).isNotEmpty(); assertThat(attackResult.isFormSent()).isFalse(); } finally { firefoxFactory.returnWebDriver(driver); } }
From source file:com.watchrabbit.scanner.supervisor.service.SupervisorServiceImpl.java
License:Apache License
@Override public void inspectSite(String addressId, String address, RemoteWebDriver driver) { LOGGER.debug("Page {} loaded", address); List<String> values = fallbackValueGeneratorStrategy.prepareValues(driver); List<WebElement> elements = driver.findElements(By.xpath("//form")); shuffle(elements);/*from www.j a v a 2s . c om*/ elements.stream().filter(this::isOpenForAttack).findAny() .ifPresent(form -> inspectForm(addressId, form, address, driver, values)); }