@InteractiveMethod
 public void invite(String eMail) {
   Actions a = new Actions(getWrappedDriver());
   invite.getWrappedElement().click();
   a.sendKeys(invite.getWrappedElement(), eMail, Keys.ENTER);
   a.perform();
 }
 @Override
 public boolean sendKeys(WebLocator el, java.lang.CharSequence... charSequences) {
   boolean sendKeys = false;
   if (ensureExists(el)) {
     try {
       el.currentElement.sendKeys(charSequences);
       sendKeys = true;
     } catch (ElementNotVisibleException e) {
       try {
         sendKeys = tryAgainDoSendKeys(el, charSequences);
       } catch (ElementNotVisibleException ex) {
         try {
           mouseOver(el);
           sendKeys = tryAgainDoSendKeys(el, charSequences);
         } catch (ElementNotVisibleException exc) {
           LOGGER.error("final ElementNotVisibleException in sendKeys: {}", el, exc);
           throw exc;
         }
       }
     } catch (WebDriverException e) {
       // TODO this fix is for Chrome
       Actions builder = new Actions(driver);
       builder.click(el.currentElement);
       builder.sendKeys(charSequences);
       sendKeys = true;
     }
   }
   return sendKeys;
 }
  @Test
  public void testDataViewTreeMapPopUpData() {
    searchByLinkAndClick(CLUSTER_VIEW_LABEL);
    searchByLinkAndClick(DATA_DROPDOWN_ID);
    WebElement TreeMapMember = driver.findElement(By.id("GraphTreeMapClusterData-canvas"));
    Actions builder = new Actions(driver);
    builder.clickAndHold(TreeMapMember).perform();
    String RegionType =
        driver
            .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div/div[2]/div"))
            .getText();
    String regionType = JMXProperties.getInstance().getProperty("region.R2.regionType");
    Assert.assertEquals(regionType, RegionType);

    String EntryCount =
        driver
            .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[2]/div[2]/div"))
            .getText();
    String entryCount = JMXProperties.getInstance().getProperty("region.R2.systemRegionEntryCount");
    Assert.assertEquals(entryCount, EntryCount);

    String EntrySizetemp =
        driver
            .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[3]/div[2]/div"))
            .getText();
    float EntrySize = Float.parseFloat(EntrySizetemp);
    float entrySize =
        Float.parseFloat(JMXProperties.getInstance().getProperty("region.R2.entrySize"));
    entrySize = entrySize / 1024 / 1024;
    entrySize = Float.parseFloat(new DecimalFormat("##.####").format(entrySize));
    Assert.assertEquals(entrySize, EntrySize);
    builder.moveToElement(TreeMapMember).release().perform();
  }
  @Override
  public void keyUp(String locator, String keySequence) {
    WebElement webElement = getWebElement(locator);

    if (keySequence.startsWith("\\")) {
      int index = GetterUtil.getInteger(keySequence.substring(1));

      Keys keys = _keysArray[index];

      if ((index >= 48) && (index <= 90)) {
        webElement.sendKeys(StringPool.ASCII_TABLE[index]);
      } else if ((index == 16) || (index == 17) || (index == 18)) {
        WrapsDriver wrapsDriver = (WrapsDriver) webElement;

        WebDriver webDriver = wrapsDriver.getWrappedDriver();

        Actions actions = new Actions(webDriver);

        actions.keyUp(webElement, keys);

        Action action = actions.build();

        action.perform();
      } else {
        webElement.sendKeys(keys);
      }
    } else {
      webElement.sendKeys(keySequence);
    }
  }
  @Override
  public void doubleClickAt(String locator, String coordString) {
    WebElement webElement = getWebElement(locator);

    WrapsDriver wrapsDriver = (WrapsDriver) webElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    if (coordString.contains(",")) {
      String[] coords = coordString.split(",");

      int x = GetterUtil.getInteger(coords[0]);
      int y = GetterUtil.getInteger(coords[1]);

      actions.moveToElement(webElement, x, y);

      actions.doubleClick();
    } else {
      actions.doubleClick(webElement);
    }

    Action action = actions.build();

    action.perform();
  }
  @Test
  @Ignore(
      "I would love for this to work consistently but it fails too often between releases to use as an example")
  public void multiSelectWithUserInteractions() {

    WebElement multiSelect;

    multiSelect = driver.findElement(By.cssSelector("select[multiple='multiple']"));
    List<WebElement> multiSelectOptions = multiSelect.findElements(By.tagName("option"));

    // in real life, clicking on a multi select item without holding down
    // CTRL will deselect all others and select only that one item

    Actions actions = new Actions(driver);

    actions
        .click(multiSelectOptions.get(0))
        .click(multiSelectOptions.get(1))
        .click(multiSelectOptions.get(2))
        .perform();

    clickSubmitButton();

    new WebDriverWait(driver, 10).until(ExpectedConditions.titleIs("Processed Form Details"));

    assertEquals(
        "Expected only 1 match",
        1,
        driver.findElements(By.cssSelector("[id^='_valuemultipleselect']")).size());
  }
  @Override
  public void clickAt(String locator, String coordString) {
    if (locator.contains("x:")) {
      String url = getHtmlNodeHref(locator);

      open(url);
    } else {
      WebElement webElement = getWebElement(locator);

      if (coordString.contains(",")) {
        WrapsDriver wrapsDriver = (WrapsDriver) webElement;

        WebDriver webDriver = wrapsDriver.getWrappedDriver();

        Actions actions = new Actions(webDriver);

        String[] coords = coordString.split(",");

        int x = GetterUtil.getInteger(coords[0]);
        int y = GetterUtil.getInteger(coords[1]);

        actions.moveToElement(webElement, x, y);
        actions.click();

        Action action = actions.build();

        action.perform();
      } else {
        webElement.click();
      }
    }
  }
  public void hoverClickAndViewStudentPhotoOnHeading(int panelHeadingIndex, String urlRegex)
      throws Exception {
    JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver;
    String idOfPanelHeading = "panelHeading-" + panelHeadingIndex;
    WebElement photoDiv =
        browser
            .driver
            .findElement(By.id(idOfPanelHeading))
            .findElement(By.className("profile-pic-icon-hover"));
    jsExecutor.executeScript("arguments[0].scrollIntoView(true);", photoDiv);
    Actions actions = new Actions(browser.driver);
    actions.moveToElement(photoDiv).perform();
    waitForElementPresence(By.cssSelector(".popover-content"));

    jsExecutor.executeScript(
        "document.getElementsByClassName('popover-content')[0]"
            + ".getElementsByTagName('a')[0].click();");

    waitForElementPresence(By.cssSelector(".popover-content > img"));

    AssertHelper.assertContainsRegex(
        urlRegex,
        browser
            .driver
            .findElements(By.cssSelector(".popover-content > img"))
            .get(0)
            .getAttribute("src"));

    jsExecutor.executeScript(
        "document.getElementsByClassName('popover')[0].parentNode.removeChild(document.getElementsByClassName('popover')[0])");
  }
Exemple #9
0
 /**
  * use to do mouse over the element
  *
  * @param elem
  */
 public void setHoverOverElement(String elem) {
   Actions builder = new Actions(driver);
   // find the element a 2nd time which helps get around the IE hover issues by focusing the
   // element
   WebElement element = driver.findElement(By.className(elem));
   builder.moveToElement(element).build().perform();
 }
  public void hoverAndViewStudentPhotoOnBody(int panelBodyIndex, String urlRegex) throws Exception {
    String idOfPanelBody = "panelBodyCollapse-" + panelBodyIndex;
    WebElement photoLink =
        browser
            .driver
            .findElements(By.cssSelector('#' + idOfPanelBody + "> .panel-body > .row"))
            .get(0)
            .findElements(By.className("profile-pic-icon-hover"))
            .get(0);
    Actions actions = new Actions(browser.driver);
    actions.moveToElement(photoLink).perform();

    waitForElementPresence(By.cssSelector(".popover-content > img"));
    ThreadHelper.waitFor(500);

    AssertHelper.assertContainsRegex(
        urlRegex,
        browser
            .driver
            .findElements(By.cssSelector(".popover-content > img"))
            .get(0)
            .getAttribute("src"));

    JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver;
    jsExecutor.executeScript(
        "document.getElementsByClassName('popover')[0].parentNode.removeChild(document.getElementsByClassName('popover')[0])");
  }
Exemple #11
0
  // W-1625895: Safari WebDriver bug- cannot right click because interactions API not implemented
  @ExcludeBrowsers({
    BrowserType.IPAD,
    BrowserType.IPHONE,
    BrowserType.SAFARI,
    BrowserType.ANDROID_PHONE,
    BrowserType.ANDROID_TABLET
  })
  public void testBaseMouseClickEventValue() throws Exception {
    open(TEST_CMP);
    WebElement input = findDomElement(By.cssSelector(".keyup2"));
    WebElement outputValue = findDomElement(By.cssSelector(".outputValue"));

    // IE < 9 uses values 1, 2, 4 for left, right, middle click (respectively)
    String expectedVal =
        (BrowserType.IE7.equals(getBrowserType()) || BrowserType.IE8.equals(getBrowserType()))
            ? "1"
            : "0";
    input.click();
    assertEquals("Left click not performed ", expectedVal, outputValue.getText());

    // right click behavior
    Actions actions = new Actions(getDriver());
    actions.contextClick(input).perform();
    assertEquals("Right click not performed ", "2", outputValue.getText());
  }
 public static void main(String... args) {
   WebDriver driver = new FirefoxDriver();
   driver.get("file:///home/daz/Downloads/WebDriver/8850OS_Code/Chapter%202/HTML/DragMe.html");
   WebElement dragMe = driver.findElement(By.id("draggable"));
   Actions builder = new Actions(driver);
   builder.dragAndDropBy(dragMe, 300, 200).perform();
 }
 public void clickForRadio(final WebElement element) {
   element.click();
   if (!element.isSelected()) {
     Actions action = new Actions(driver);
     action.click(element).perform();
   }
 }
  public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.get("http://facebook.com");

    driver.findElement(By.xpath("//input[@id='email']")).sendKeys("*****@*****.**");
    driver.findElement(By.xpath("//input[@id='pass']")).sendKeys("Temp@123");
    driver.findElement(By.xpath("//input[@id='pass']")).sendKeys(Keys.ENTER);

    driver.findElement(By.xpath("//div[@id='pagelet_welcome_box']/div/a")).click();
    driver.findElement(By.xpath("//div[@id='fbTimelineHeadline']/div[2]/div/a[4]")).click();

    List<WebElement> friends = driver.findElements(By.xpath("//div[@class='fsl fwb fcb']/a"));
    System.out.println("Total friends -> " + friends.size());
    int newFriends = friends.size(); // 20 40 60
    Actions act = new Actions(driver);

    int oldFriends = 0; // 0 20 40 60
    while (newFriends != oldFriends) {
      oldFriends = newFriends;
      WebElement lastFriend = friends.get(friends.size() - 1);
      act.moveToElement(lastFriend).build().perform(); // 20th
      Thread.sleep(3000);
      friends = driver.findElements(By.xpath("//div[@class='fsl fwb fcb']/a"));
      newFriends = friends.size();
      System.out.println("Total friends -> " + friends.size());
    }

    System.out.println("FINAL Total friends -> " + friends.size());
    for (int i = 0; i < friends.size(); i++) {
      System.out.println(friends.get(i).getText());
    }
  }
  /**
   * Finds the menu that can be used by the owner to control the participant. Hovers over it. Finds
   * the mute link and mute it. Then checks in the second participant page whether it is muted
   */
  public void ownerMutesParticipantAndCheck() {
    System.err.println("Start ownerMutesParticipantAndCheck.");

    WebDriver owner = ConferenceFixture.getOwner();

    WebElement elem =
        owner.findElement(By.xpath("//div[@class='remotevideomenu']/i[@class='fa fa-angle-down']"));

    Actions action = new Actions(owner);
    action.moveToElement(elem);
    action.perform();

    TestUtils.waitForDisplayedElementByXPath(
        owner, "//ul[@class='popupmenu']/li/a[@class='mutelink']", 5);

    owner.findElement(By.xpath("//ul[@class='popupmenu']/li/a[@class='mutelink']")).click();

    // and now check whether second participant is muted
    TestUtils.waitForElementByXPath(
        ConferenceFixture.getSecondParticipant(),
        "//span[@class='audioMuted']/i[@class='icon-mic-disabled']",
        5);

    action.release();
  }
  public void clickViewPhotoLink(int panelBodyIndex, String urlRegex) throws Exception {
    String idOfPanelBody = "panelBodyCollapse-" + panelBodyIndex;
    WebElement photoCell =
        browser
            .driver
            .findElement(By.id(idOfPanelBody))
            .findElements(By.cssSelector(".profile-pic-icon-click"))
            .get(0);
    JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver;
    jsExecutor.executeScript(
        "document.getElementById('"
            + idOfPanelBody
            + "')"
            + ".getElementsByClassName('profile-pic-icon-click')[0]"
            + ".getElementsByTagName('a')[0].click();");
    Actions actions = new Actions(browser.driver);

    actions.moveToElement(photoCell).perform();
    waitForElementPresence(By.cssSelector(".popover-content > img"));

    List<WebElement> photos = browser.driver.findElements(By.cssSelector(".popover-content > img"));
    AssertHelper.assertContainsRegex(urlRegex, photos.get(photos.size() - 1).getAttribute("src"));

    actions.moveByOffset(100, 100).click().perform();
  }
 private void TypesOfSchool() throws IOException {
   // Click Type of School
   driver.findElement(By.cssSelector("strong")).click();
   // Click Private
   driver.findElement(By.id("edit-public-private-private")).click();
   // Move School Size Slider
   // TODO Slider not working properly
   WebElement Slider1 = driver.findElement(By.id("population_jq_slider"));
   Actions moveSlider1 = new Actions(driver);
   Action action1 = moveSlider1.dragAndDropBy(Slider1, 0, 10).build();
   action1.perform();
   // Select Religious Affiliation
   new Select(driver.findElement(By.id("edit-religious-affiliation")))
       .selectByVisibleText("Church of Christ");
   // Move Tuition Range Slider
   // TODO Slider not working properly
   WebElement Slider2 = driver.findElement(By.id("tuition_range_jq_slider"));
   Actions moveSlider2 = new Actions(driver);
   Action action2 = moveSlider2.dragAndDropBy(Slider2, 0, 10).build();
   action2.perform();
   // Click Apply
   driver.findElement(By.id("edit-type-of-school-apply-filter")).click();
   // Check Result Received or Not
   try {
     assertTrue(
         func.isTextPresent(driver.findElement(By.className("search-total-results")).getText()));
   } catch (Error e) {
     verificationErrors.append(e.toString());
   }
   // Click All Selections
   driver.findElement(By.linkText("Clear All Selections")).click();
 }
 protected void appendText(WebElement inputElement, String text) {
   Actions actions = new Actions(driver);
   actions.moveToElement(inputElement);
   actions.click();
   actions.sendKeys(text);
   actions.perform();
 }
 /**
  * Mouse Over on the the given element.
  *
  * @return Parent instance
  */
 public ParentPanel mouseOver() {
   getWebElement().getSize(); // for scroll to object
   logAction(this, getParentClassName(), "mouseOver");
   Actions builder = new Actions(getDriver());
   builder.moveToElement(getWebElement()).build().perform();
   return parent;
 }
 /**
  * Performs a right-click at the current mouse location.
  *
  * @return Parent instance
  */
 public ParentPanel rightClick() {
   getWebElement().getSize(); // for scroll to object
   logAction(this, getParentClassName(), "rightClick");
   Actions builder = new Actions(getDriver());
   builder.contextClick(getWebElement()).perform();
   return parent;
 }
Exemple #21
0
 protected void forcePageLoad() throws Exception {
   logMsg("Forcing page load by sending END key to folder list");
   WebElement e = getJspTestUtils().findElement(By.id("folderList"));
   Actions clicker = new Actions(getJspTestUtils().getDriver());
   clicker.moveToElement(e);
   clicker.sendKeys(e, Keys.END);
   clicker.perform();
 }
  /**
   * @param model Lets say there is header menu bar, on hovering the mouse, drop down should be
   *     displayed
   */
  public void dropDownByMouseHover(MethodParameters model) {
    Actions action = new Actions(WebDriverClass.getInstance());

    action.moveToElement(model.getElement().get(0)).perform();
    WebElement subElement = WebDriverClass.getInstance().findElement(By.xpath(model.getData()));
    action.moveToElement(subElement);
    action.click().build().perform();
  }
Exemple #23
0
  // 注销
  public void logout() throws Exception {

    dr.switchTo().defaultContent();
    Actions actLogout = new Actions(dr);
    actLogout.click(dr.findElement(By.xpath("//a[contains(text(),'注销')]"))).perform();
    System.out.println("logout-----");
    Thread.sleep(1000);
  }
 @Test
 public void dragandDropTest() {
   Actions action = new Actions(driver);
   driver.switchTo().frame(0);
   WebElement source = driver.findElement(By.id("draggable"));
   WebElement target = driver.findElement(By.id("droppable"));
   action.dragAndDrop(source, target).build().perform();
 }
 public static void hoverClick(WebDriver driver, String hover) throws InterruptedException {
   Thread.sleep(2000);
   Actions builder = new Actions(driver);
   Actions hoverOverRegistrar = builder.moveToElement(driver.findElement(By.xpath(hover)));
   hoverOverRegistrar.perform();
   driver.findElement(By.linkText("Sign Out")).click();
   Thread.sleep(1000);
 }
Exemple #26
0
 public void rightClick() {
   invoker.doJAction(
       "Right click on Element",
       () -> {
         getWebElement().getSize(); // for scroll to object
         Actions builder = new Actions(getDriver());
         builder.contextClick(getWebElement()).perform();
       });
 }
 /**
  * Focus on the Element(WebElement)
  *
  * @return Parent instance
  */
 public ParentPanel focus() {
   Dimension size = getWebElement().getSize(); // for scroll to object
   logAction(this, getParentClassName(), "focus");
   Actions builder = new Actions(getDriver());
   org.openqa.selenium.interactions.Action focus =
       builder.moveToElement(getWebElement(), size.width / 2, size.height / 2).build();
   focus.perform();
   return parent;
 }
  public static void main(String... args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("file://C:/DragAndDrop.html");
    WebElement src = driver.findElement(By.id("draggable"));
    WebElement trgt = driver.findElement(By.id("droppable"));

    Actions builder = new Actions(driver);
    builder.dragAndDrop(src, trgt).perform();
  }
Exemple #29
0
 public void clickCenter() {
   invoker.doJAction(
       "Click in Center of Element",
       () -> {
         getWebElement().getSize(); // for scroll to object
         Actions builder = new Actions(getDriver());
         builder.click(getWebElement()).perform();
       });
 }
Exemple #30
0
 public void mouseOver() {
   invoker.doJAction(
       "Move mouse over Element",
       () -> {
         getWebElement().getSize(); // for scroll to object
         Actions builder = new Actions(getDriver());
         builder.moveToElement(getWebElement()).build().perform();
       });
 }