List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
From source file:org.vige.rubia.selenium.adminpanel.action.LockForum.java
License:Apache License
private static WebElement findForum(WebDriver driver, Forum forum) { List<WebElement> moveForums = driver.findElements(tagName("strong")); WebElement foundElement = null;/*from w ww .j av a 2 s. com*/ for (WebElement moveForum : moveForums) if (moveForum.getText().equals(forum.getName())) foundElement = moveForum.findElement(xpath("../..")); return foundElement; }
From source file:org.vige.rubia.selenium.forum.action.CreateAttachment.java
License:Apache License
public static String[] addAttachments(WebDriver driver, Post post) { Collection<Attachment> attachments = post.getAttachments(); if (attachments != null) { int i = 0; int oldCommentsCount = driver.findElements(className(FILE_COMMENT_INPUT_TEXT)).size(); for (Attachment attachment : attachments) { File file;/*from w w w . ja v a 2 s.c o m*/ try { String oldName = attachment.getName(); file = File.createTempFile(oldName, ".txt"); OutputStream out = new FileOutputStream(file); attachment.setContent(oldName.getBytes()); out.write(attachment.getContent()); out.close(); attachment.setName(file.getAbsolutePath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String comment = attachment.getComment(); WebElement attachmentInput = driver.findElement(className(FILE_CHOOSE_BUTTON)); attachmentInput.sendKeys(attachment.getName()); WebElement commentInput = addComment(driver, oldCommentsCount + i); i++; commentInput.sendKeys(comment); } } List<WebElement> attachmentResultList = driver.findElements(className(RESULT_ATTACHMENT_LIST)); String[] result = new String[attachmentResultList.size()]; for (int i = 0; i < result.length; i++) result[i] = attachmentResultList.get(i).getText(); return result; }
From source file:org.vige.rubia.selenium.forum.action.CreateAttachment.java
License:Apache License
public static WebElement addComment(WebDriver driver, int index) { WebElement commentInput = null;/*from www .j a v a 2 s . c o m*/ try { commentInput = driver.findElements(className(FILE_COMMENT_INPUT_TEXT)).get(index); } catch (IndexOutOfBoundsException ex) { } if (commentInput == null) return addComment(driver, index); else return commentInput; }
From source file:org.vige.rubia.selenium.forum.action.CreatePoll.java
License:Apache License
public static String[] createOptions(WebDriver driver, Poll poll) { WebElement questionInput = driver.findElement(id(QUESTION_INPUT_TEXT)); questionInput.sendKeys(poll.getTitle()); List<PollOption> options = poll.getOptions(); if (options != null) for (int i = 0; i < options.size(); i++) { WebElement optionInput = null; WebElement optionButton = null; optionInput = driver.findElement(id(NEW_OPTION_INPUT_TEXT)); optionInput.sendKeys(options.get(i).getQuestion()); optionButton = driver.findElements(className(ADD_OPTION_BUTTON)).get(i * 2); optionButton.click();//from ww w.j a v a 2 s .c o m } WebElement[] updatedElements = new WebElement[options.size()]; for (int i = 0; i < options.size(); i++) updatedElements[i] = driver .findElement(xpath("//input[@value='" + options.get(i).getQuestion() + "']")); String[] results = new String[updatedElements.length]; for (int i = 0; i < updatedElements.length; i++) results[i] = updatedElements[i].getAttribute("value"); return results; }
From source file:org.vige.rubia.selenium.forum.action.CreateTopic.java
License:Apache License
public static String createTopic(WebDriver driver, Topic topic) { WebElement home = driver.findElement(linkText(HOME_LINK)); home.click();/*from ww w . ja v a 2s . c o m*/ WebElement forumEl = driver.findElement(linkText(topic.getForum().getName())); forumEl.click(); WebElement createTopic = driver.findElement(xpath(CREATE_TOPIC_LINK)); createTopic.click(); WebElement subjectInput = driver.findElement(id(SUBJECT_INPUT_TEXT)); subjectInput.sendKeys(topic.getSubject()); driver.switchTo().frame(driver.findElement(xpath(BODY_INPUT_TEXT))); WebElement bodytInput = driver.findElement(cssSelector("body")); bodytInput.sendKeys(topic.getPosts().get(0).getMessage().getText()); driver.switchTo().defaultContent(); WebElement topicTypeInput = null; topicTypeInput = driver.findElements(xpath("//input[@type='radio']")).get(topic.getType().getValue()); topicTypeInput.click(); createOptions(driver, topic.getPoll()); addAttachments(driver, topic.getPosts().get(0)); WebElement operationButton = driver.findElement(id(SUBMIT_BUTTON)); operationButton.click(); if (topic.getPosts().size() > 1) { for (int i = 1; i < topic.getPosts().size(); i++) { Post post = topic.getPosts().get(i); if (post.getTopic() == null) post.setTopic(topic); createPost(driver, post); } } WebElement resultCreateTopic = driver.findElement(linkText(topic.getSubject())); String updatedTopic = resultCreateTopic.getText(); return updatedTopic; }
From source file:org.vige.rubia.selenium.forum.action.RemoveAttachment.java
License:Apache License
public static String removeAllAttachments(WebDriver driver, Post post) { WebElement attachmentButton = driver.findElement(className(ATTACHMENTS_DELETE_BUTTON)); attachmentButton.click();/*from w ww.jav a 2s. c o m*/ String message = ""; int commentSize = driver.findElements(className(FILE_COMMENT_INPUT_TEXT)).size(); if (commentSize == 2) message = OK; WebElement updateButton = driver.findElement(id(UPDATE_BUTTON)); updateButton.click(); return message; }
From source file:org.vige.rubia.selenium.forum.action.RemovePoll.java
License:Apache License
public static String removePoll(WebDriver driver, Topic topic) { goTo(driver, topic);// w w w . j a v a 2 s . com WebElement updateTopicButton = driver.findElements(xpath("//tbody")).get(2) .findElement(id(UPDATE_TOPIC_BUTTON)).findElement(xpath("ul/a[1]")); updateTopicButton.click(); List<PollOption> options = topic.getPoll().getOptions(); if (options != null) for (int i = 0; i < options.size(); i++) { WebElement optionButton = driver.findElement(id(DELETE_OPTION_BUTTON)); optionButton.click(); } WebElement questionText = driver.findElement(id(QUESTION_INPUT_TEXT)); questionText.clear(); WebElement confirmUpdateButton = driver.findElement(id(CONFIRM_UPDATE_TOPIC_BUTTON)); confirmUpdateButton.click(); String result; try { result = driver.findElement(className(RESULT_REMOVE_POLL)).getText(); } catch (NoSuchElementException ex) { result = OK; } return result; }
From source file:org.vige.rubia.selenium.forum.action.UpdatePoll.java
License:Apache License
public static Poll addOptions(WebDriver driver, Poll poll) { WebElement updateTopicButton = driver.findElements(xpath("//tbody")).get(2) .findElement(id(UPDATE_TOPIC_BUTTON)).findElement(xpath("ul/a[1]")); updateTopicButton.click();//from w w w .j a va 2 s .c o m List<PollOption> options = poll.getOptions(); if (options != null) for (int i = 0; i < options.size(); i++) { WebElement optionInput = null; WebElement optionButton = null; optionInput = driver.findElement(id(OPTION_ADD_INPUT_TEXT)); optionInput.sendKeys(options.get(i).getQuestion()); optionButton = driver.findElement( xpath("//input[starts-with(@value,'" + ADD_OPTION_BUTTON.substring(0, 11) + "')]")); optionButton.click(); } WebElement submitTopicButton = driver.findElement(id(SUBMIT_TOPIC_BUTTON)); submitTopicButton.click(); Poll updatedPoll = getPollOfCurrentTopic(driver); return updatedPoll; }
From source file:org.vige.rubia.selenium.forum.action.UpdatePoll.java
License:Apache License
public static Poll vote(WebDriver driver, Poll poll, int indexVote) { List<WebElement> optionsToVoteList = driver.findElements(className(OPTIONS_TO_VOTE_LIST)); optionsToVoteList.get(indexVote).findElement(xpath("input")).click(); WebElement voteButton = driver.findElement(className(VOTE_BUTTON)); voteButton.click();/* w ww . j a v a2s . co m*/ Poll updatedPoll = getPollOfCurrentTopic(driver); return updatedPoll; }
From source file:org.vige.rubia.selenium.forum.action.UpdatePoll.java
License:Apache License
public static Poll deleteOptions(WebDriver driver, Poll poll) { WebElement updateTopicButton = driver.findElements(xpath("//tbody")).get(2) .findElement(id(UPDATE_TOPIC_BUTTON)).findElement(xpath("ul/a[1]")); updateTopicButton.click();// w ww . jav a 2s.c o m List<PollOption> options = poll.getOptions(); if (options != null) for (int i = 0; i < options.size(); i++) { WebElement optionButton = null; optionButton = driver.findElement(xpath("//input[@value='" + options.get(i).getQuestion() + "']/../input[@value='" + DELETE_OPTION_BUTTON + "']")); optionButton.click(); } WebElement submitTopicButton = driver.findElement(id(SUBMIT_TOPIC_BUTTON)); submitTopicButton.click(); Poll updatedPoll = getPollOfCurrentTopic(driver); return updatedPoll; }