List of usage examples for org.openqa.selenium Keys RETURN
Keys RETURN
To view the source code for org.openqa.selenium Keys RETURN.
Click Source Link
From source file:selenium_tumblr_test.DashboardPage.java
License:Open Source License
public void addNewLink(String url) { // going to this URL would have the same effect //driver.get("https://www.tumblr.com/blog/runspotgo/new/quote"); // click new link newLinkButton.click();//from w ww . j av a 2 s . c o m // fill in link URL WebElement textUrl = driver.switchTo().activeElement(); textUrl.sendKeys(url + Keys.RETURN); // wait until text element visible waitForElementToBeVisible(byLinkURL); // post & wait clickThenWaitForElementToDisappear(byPost); }
From source file:TBR.Regression_Testcases.CreateNewCandidate.java
@Test(dataProvider = "getCreateNewCandidateData") public void createNewCandidate(Hashtable<String, String> data) throws InterruptedException { openBrowser();/*from w w w . ja v a 2 s. c o m*/ driver.get(CONFIG.getProperty("testSiteName")); login_Valid(); //login_Kevin(); getObject("candLinkX").click(); getObject("addNewCandidateX").click(); waitForElementClickableId(10, "candidateNameId"); //waitForElementClickableId(10, "candidateNameId"); //moves on to step 1 Basic Information //explicitWaitId("candidateNameId"); getObjectById("candidateNameId").sendKeys(data.get("CandidateName")); Thread.sleep(5000); String candidateName = getObjectById("candidateNameId").getAttribute("value"); System.out.println("name of the new candidate is= " + candidateName); getObjectById("candidateEmailId").sendKeys(data.get("CandidateEmail")); getObjectById("candidatePhoneNumberId").sendKeys(data.get("PhoneNumber")); /*getObject("candidateMonthX").sendKeys(data.get("DobMonth")); //getObjectById("candidateYearX").click(); getObject("candidateYearX").sendKeys(data.get("DobYear")); getObject("candidateDayDateX").click();*/ getObjectById("candidateDobId").click(); Thread.sleep(5000); Select yearDob = new Select(getObject("candidateYearX")); yearDob.selectByValue("2009"); Select monthDob = new Select(getObjectByCss("candidateMonthCSS")); monthDob.selectByVisibleText("Oct"); getObject("candidateDayDateX").click(); getObjectById("candidateAddressId").click(); getObjectById("candidateAddressId").sendKeys(data.get("CandidateAddress")); Actions hover = new Actions(driver); WebElement elementToHover = getObject("candidateNextStep1X"); hover.moveToElement(elementToHover); hover.build().perform(); Thread.sleep(3000); getObject("candidateNextStep1X").click(); //moving on to Step 2 LogIn Details getObjectById("candidateUsernameId").sendKeys(data.get("CandidateUsername")); getObjectById("candidatePasswordId").sendKeys(data.get("CandidatePassword")); Actions hove = new Actions(driver); WebElement elementToHov = getObject("candidateNextStep1X"); hove.moveToElement(elementToHov); hove.build().perform(); //getObjectByCss("candidateNextStepCss").click(); Actions hover3 = new Actions(driver); WebElement elementToHover3 = getObjectByCss("candidateNextStepCss"); hover3.moveToElement(elementToHover3); hover3.build().perform(); Thread.sleep(4000); getObjectByCss("candidateNextStepCss").click(); System.out.println("clicked on next in step 2"); //moving on to Step 3 Employment Information waitForElementClickableId(10, "candidateNiNumberId"); getObjectById("candidateNiNumberId").sendKeys(data.get("NiNumber")); getObjectById("candidateStatusId").sendKeys(data.get("CandidateStatus")); getObject("candidateNextStep3X").click(); //moving on to Step 4 Social Media (Optional) getObjectById("candidateFacebookId").sendKeys(data.get("Facebook")); getObjectById("candidateTwitterId").sendKeys(data.get("Twitter")); getObjectById("candidateLinkedinId").sendKeys(data.get("LinkedIn")); getObjectById("candidateSkypeId").sendKeys(data.get("Skype")); getObject("candidateNextStep4X").click(); //moving on to Step 5 Criteria getObject("candidateCategoryX").click(); getObject("candidateCategoryX").sendKeys(data.get("Category")); getObject("candidateCategoryX").sendKeys(Keys.RETURN); //Thread.sleep(3000); /*the below two lines are for live server*/ //getObjectById("candidateLicenseId").click(); //getObjectById("candidateLicenseId").sendKeys(data.get("driverlicense")); //getObjectById("candidateLicenseId").sendKeys(Keys.RETURN); /*end of live server code*/ getObject("candidateCustomAttributeShowX").click(); explicitWaitId("candidatePassportId"); getObjectById("candidatePassportId").click(); Select month = new Select(getObject("candidatePassportMonthX")); month.selectByVisibleText("Oct"); Select year = new Select(getObject("candidatePassportYearX")); year.selectByValue("2020"); getObject("candidatePassportDateX").click(); Thread.sleep(5000); getObjectById("candidateManualCertId").click(); Select month1 = new Select(getObject("candidateManualMonthX")); month1.selectByVisibleText("Jul"); Select year1 = new Select(getObject("candidateManualYearX")); year1.selectByValue("2015"); getObject("candidateManualDateX").click(); getObjectById("candidateGardaVettingId").sendKeys(data.get("GardaVetting")); getObjectById("candidateTrainingId").sendKeys(data.get("TrainingComplete")); getObjectById("candidateProofOfRightToWorkId").sendKeys(data.get("ProofRightToWork")); getObjectById("candidateCertificationExpiry").click(); Select month2 = new Select(getObject("candidateCertificationMonthX")); month2.selectByVisibleText("Sep"); Select year2 = new Select(getObject("candidateCertificationYearX")); year2.selectByValue("2018"); getObject("candidateCertificationDateX").click(); getObject("candidateFinishStep5X").click(); Thread.sleep(10000); explicitWaitXpath("candLinkX"); //back to dash board //getObject("candLinkX").click(); //explicitWaitXpath("allCandidatesX"); getObject("allCandidatesX").click(); //moves on to candidate list wizard //explicitWaitXpath("searchCandidateX"); getObject("searchCandidateX").click(); //explicitWaitXpath("searchCandidateX"); getObject("searchCandidateX").sendKeys(candidateName); //explicitWaitXpath("candidateMatchX"); Thread.sleep(5000); String candidateNameAppeared = getObject("candidateMatchX").getText(); System.out.println("candidate appeared on the screen is = " + candidateNameAppeared); Assert.assertEquals(candidateNameAppeared, candidateName); System.out.println("new candidate saved successfully"); }
From source file:wsattacker.sso.openid.attacker.evaluation.strategies.InjectJavaScriptLoginStrategy.java
License:Open Source License
@Override public LoginResult login(User user, ServiceProvider serviceProvider) { // before loginAndDetermineAuthenticatedUser remove all cookies SeleniumBrowser.deleteAllCookies();/* ww w .ja v a2s. c o m*/ // copy log entries before login List<RequestLogEntry> logEntriesBeforeLogin = new ArrayList<>(RequestLogger.getInstance().getEntryList()); // open url WebDriver driver = SeleniumBrowser.getWebDriver(); driver.get(serviceProvider.getUrl()); /* Search the page for the OpenID input field. According to the standard it should be called "openid_identifier" but some other frequent names are also tried. */ WebElement element = null; String[] possibleNames = { "openid_identifier", "openid", "openID", "openid_url", "openid:url", "user", "openid-url", "openid-identifier", "oid_identifier", "ctl00$Column1Area$OpenIDControl1$openid_url", "user_input", "openIdUrl" }; for (String possibleName : possibleNames) { try { element = driver.findElement(By.name(possibleName)); System.out.println("Find OpenID field with name: " + possibleName); break; } catch (NoSuchElementException exception) { //System.out.println("Cannot find: " + possibleName); } } // save old XRDS lcoation String oldIdentity = OpenIdServerConfiguration.getAttackerInstance().getHtmlConfiguration().getIdentity(); /* If an input field is found, it is filled with the OpenID identifier. Selenium cannot set text of hidden input field, consequently, JavaScript is injected which performs this task. */ if (element != null) { JavascriptExecutor jse = (JavascriptExecutor) driver; // set text of text field switch (user) { case VICTIM: jse.executeScript("arguments[0].value='" + serviceProvider.getVictimOpenId() + "'", element); break; case ATTACKER: jse.executeScript("arguments[0].value='" + serviceProvider.getAttackerOpenId() + "'", element); break; case ATTACKER_RANDOM: String attackerOpenId = serviceProvider.getAttackerOpenId(); if (attackerOpenId.endsWith("/")) { attackerOpenId = attackerOpenId.substring(0, attackerOpenId.length() - 1); } String randomAttackerIdentity = attackerOpenId + RandomStringUtils.random(10, true, true); OpenIdServerConfiguration.getAttackerInstance().getHtmlConfiguration() .setIdentity(randomAttackerIdentity); jse.executeScript("arguments[0].value='" + randomAttackerIdentity + "'", element); break; } // special case: owncloud if (driver.getCurrentUrl().contains("owncloud")) { // set arbitrary password WebElement passwordElement = driver.findElement(By.id("password")); passwordElement.clear(); passwordElement.sendKeys("xyz"); WebElement submitElement = driver.findElement(By.id("submit")); jse.executeScript("var element = arguments[0]; element.removeAttribute('id');", submitElement); } // submit form if (element.isDisplayed()) { // element.submit(); // does not work as expected element.sendKeys(Keys.RETURN); } else { jse.executeScript("var element = arguments[0];" + "while(element.tagName != 'FORM') {" + "element = element.parentNode;" + "console.log(element);" + "}" + "element.submit();", element); } } // click on accept in modal alert window (if present) try { driver.switchTo().alert().accept(); } catch (NoAlertPresentException ex) { // do nothing } // wait 10 seconds: hopefully, all redirects are performed then try { Thread.sleep(10000); } catch (InterruptedException ex) { Logger.getLogger(ServiceProvider.class.getName()).log(Level.SEVERE, null, ex); } /* determines the log entries of the current login procedure: logEntries = logEntriesAfterLogin - logEntriesBeforeLogin (subtraction of sets) */ List<RequestLogEntry> logEntriesAfterLogin = RequestLogger.getInstance().getEntryList(); List<RequestLogEntry> logEntries = (List<RequestLogEntry>) CollectionUtils.subtract(logEntriesAfterLogin, logEntriesBeforeLogin); // invert order of log - should be chronological Collections.reverse(logEntries); File screenshot = SeleniumBrowser.takeScreenshot(); String pageSource = driver.getPageSource(); // restore old XRDS location OpenIdServerConfiguration.getAttackerInstance().getHtmlConfiguration().setIdentity(oldIdentity); return new LoginResult(pageSource, logEntries, screenshot, driver.getCurrentUrl()); }