Java Code Examples for org.openqa.selenium.WebElement#click()

The following examples show how to use org.openqa.selenium.WebElement#click() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicKeyboardInterfaceTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
@NotYetImplemented(SAFARI)
@NotYetImplemented(EDGE)
public void testSendingKeysWithShiftPressed() {
  driver.get(pages.javascriptPage);

  WebElement keysEventInput = driver.findElement(By.id("theworks"));

  keysEventInput.click();

  String existingResult = getFormEvents();

  Action pressShift = getBuilder(driver).keyDown(keysEventInput, Keys.SHIFT).build();
  pressShift.perform();

  Action sendLowercase = getBuilder(driver).sendKeys(keysEventInput, "ab").build();
  sendLowercase.perform();

  Action releaseShift = getBuilder(driver).keyUp(keysEventInput, Keys.SHIFT).build();
  releaseShift.perform();

  String expectedEvents = " keydown keydown keypress keyup keydown keypress keyup keyup";
  assertThatFormEventsFiredAreExactly("Shift key not held", existingResult + expectedEvents);

  assertThat(keysEventInput.getAttribute("value")).isEqualTo("AB");
}
 
Example 2
Source File: StepUtils.java    From OpenESPI-DataCustodian-java with Apache License 2.0 5 votes vote down vote up
public static void associate(String uuid, String description) {
	clickLinkByPartialText("Add Usage Point");

	WebElement uuidElement = driver.findElement(By.name("UUID"));
	uuidElement.clear();
	uuidElement.sendKeys(uuid);

	WebElement descriptionElement = driver
			.findElement(By.id("description"));
	descriptionElement.sendKeys(description);

	WebElement create = driver.findElement(By.name("create"));
	create.click();
}
 
Example 3
Source File: ITCreateMultipleBuckets.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    // bucket cleanup

    // confirm all buckets checkbox exists
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nifi-registry-workflow-administration-buckets-list-container-column-header div.mat-checkbox-inner-container")));

    // select all buckets checkbox
    WebElement selectAllCheckbox = driver.findElement(By.cssSelector("#nifi-registry-workflow-administration-buckets-list-container-column-header div.mat-checkbox-inner-container"));
    selectAllCheckbox.click();

    // confirm actions drop down menu exists
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nifi-registry-workflow-administration-perspective-buckets-container button.mat-fds-primary")));

    // select actions drop down
    WebElement selectActions = driver.findElement(By.cssSelector("#nifi-registry-workflow-administration-perspective-buckets-container button.mat-fds-primary"));
    selectActions.click();

    // select delete
    WebElement selectDeleteBucket = driver.findElement(By.cssSelector("div.mat-menu-content button.mat-menu-item"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", selectDeleteBucket);

    // verify bucket deleted
    WebElement confirmDelete = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.fds-dialog-actions button.mat-fds-warn")));
    confirmDelete.click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[data-automation-id='no-buckets-message']")));

    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
    }
}
 
Example 4
Source File: ITCreateBucket.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    // bucket cleanup

    // confirm all buckets checkbox exists
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nifi-registry-workflow-administration-buckets-list-container-column-header div.mat-checkbox-inner-container")));

    // select all buckets checkbox
    WebElement selectAllCheckbox = driver.findElement(By.cssSelector("#nifi-registry-workflow-administration-buckets-list-container-column-header div.mat-checkbox-inner-container"));
    selectAllCheckbox.click();

    // confirm actions drop down menu exists
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nifi-registry-workflow-administration-perspective-buckets-container button.mat-fds-primary")));

    // select actions drop down
    WebElement selectActions = driver.findElement(By.cssSelector("#nifi-registry-workflow-administration-perspective-buckets-container button.mat-fds-primary"));
    selectActions.click();

    // select delete
    WebElement selectDeleteBucket = driver.findElement(By.cssSelector("div.mat-menu-content button.mat-menu-item"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", selectDeleteBucket);

    // verify bucket deleted
    WebElement confirmDelete = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.fds-dialog-actions button.mat-fds-warn")));
    confirmDelete.click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[data-automation-id='no-buckets-message']")));

    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
    }
}
 
Example 5
Source File: EvernoteAndroidTest.java    From candybean with GNU Affero General Public License v3.0 5 votes vote down vote up
public void closeWelcomeOverlay() throws CandybeanException {
	if(overlayExists()){
		try {
			WebElement welcomeOverlay = iface.wd.findElement(By.id("com.evernote:id/fd_layout"));
			WebElement closeOverlayButton = welcomeOverlay.findElement(By.className("android.widget.ImageView"));
			closeOverlayButton.click();
			iface.pause(1000);
		} catch (NoSuchElementException e) {
			return;
		}
	}
}
 
Example 6
Source File: NavigationParameterTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
public void testNavigationActionIndex() throws MalformedURLException
{
    driver.get(new URL(contextPath, "origin.xhtml").toString());

    WebElement button = driver.findElement(By.id("parameter:pb005Index"));
    button.click();
    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("indexPage"),
            "You arrived at index page")
            .apply(driver));
    System.out.println(driver.getCurrentUrl());
    Assert.assertTrue(driver.getCurrentUrl().contains("param1=staticValue2"));
}
 
Example 7
Source File: InjectionDroneTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
public void testValidator() throws MalformedURLException
{
    driver.get(new URL(contextPath, "testValidatorConverter.xhtml").toString());
    WebElement convertedValue = driver.findElement(By.id("validator:stringValue"));
    convertedValue.sendKeys("DeltaSpike");
    WebElement testConveterButton = driver.findElement(By.id("validator:testValidatorButton"));
    testConveterButton.click();
    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("messages"), "Worked").apply(driver));
}
 
Example 8
Source File: ConfigureClasspath.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** select item in the 'Select Path' form */
public void selectItemInSelectPathForm(String itemName) {
  waitItemInSelectPathForm(itemName);
  WebElement item =
      seleniumWebDriver.findElement(By.xpath(String.format(ITEM_SELECT_PATH_FORM, itemName)));
  item.click();
}
 
Example 9
Source File: WebDriverAftBase.java    From rice with Educational Community License v2.0 5 votes vote down vote up
protected void waitAndClickDropDown(String dropDownText) throws InterruptedException {
    jGrowl("Click the " + dropDownText + " drop down.");
    WebElement dropdownMenu = waitAndGetElementByAttributeValue("class", "dropdown-toggle");
    Thread.sleep(1000);
    dropdownMenu.click();
    waitAndClickByLinkText(dropDownText, "dropdown click " + dropDownText + " problem");
}
 
Example 10
Source File: DLCContentPage.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Test rerouting messages of DeadLetter Channel
 */
public String rerouteFunction(String qName) throws IOException {
    String reroutingMessageID;

    driver.findElement(By.xpath(UIElementMapper.getInstance()
                                        .getElement("mb.dlc.browse.table.choose.box.xpath"))).click();
    reroutingMessageID = driver.findElement(By.xpath(UIElementMapper.getInstance()
                                                             .getElement("mb.dlc.first.message.id"))).getText();
    driver.findElement(By.xpath(UIElementMapper.getInstance()
                                        .getElement("mb.dlc.browse.table.reroute.button"))).click();
    //select rerouteTestQueue to reroute message
    WebElement select = driver.findElement(By.xpath(UIElementMapper.getInstance()
                                                            .getElement("mb.dlc.browse.table.reroute.queue.select")));
    List<WebElement> options = select.findElements(By.tagName(UIElementMapper.getInstance()
                                                                      .getElement("mb.dlc.browse.table.reroute.queue.option")));
    for (WebElement option : options) {
        if (option.getText().equals(qName.toLowerCase())) {
            option.click();
            break;
        }
    }
    driver.findElement(By.xpath(UIElementMapper.getInstance()
                                        .getElement("mb.dlc.browse.table.reroute.confirm"))).click();
    driver.findElement(By.xpath(UIElementMapper.getInstance()
                                        .getElement("mb.dlc.browse.function.confirm"))).click();
    driver.findElement(By.xpath(UIElementMapper.getInstance()
                                        .getElement("mb.dlc.browse.function.success"))).click();
    return reroutingMessageID;
}
 
Example 11
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void getEnabled() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement button = driver.findElement(By.cssSelector("button"));
    AssertJUnit.assertEquals("Click Me!!", button.getText());
    AssertJUnit.assertEquals("true", button.getAttribute("enabled"));
    button.click();
}
 
Example 12
Source File: HomePage.java    From oxTrust with MIT License 5 votes vote down vote up
public void goToGroupsManagePage() {
	WebElement groupMenu = webDriver.findElement(By.xpath("//*[@id='menuUsers']"));
	groupMenu.click();
	WebElement subMenu = waitElement("//*[@id='subMenuLinkUsers1']");
	subMenu.click();
	fluentWait(3);
}
 
Example 13
Source File: DocumentSearchUrlParametersAft.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Test
public void testBasicSearchMode() throws InterruptedException{
    driver.get(getDocSearchURL(""));
    WebElement toggle = findModeToggleButton();
    assertSearchDetailMode(toggle, false);
    toggle.click();
    assertSearchDetailMode(findModeToggleButton(), true);
}
 
Example 14
Source File: AdfCalendar.java    From adf-selenium with Apache License 2.0 4 votes vote down vote up
public void clickDateLink(int index) {
    WebElement element = findAllDateLinks().get(index);
    element.click();
    waitForPpr();
}
 
Example 15
Source File: ProjectSourcePage.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * select type of created project
 *
 * @param source is type of the existing templates
 */
public void selectSourceTab(Sources source) {
  WebElement sourceTab =
      seleniumWebDriver.findElement(By.id(String.format(Locators.SAMPLES_BUTTON, source.title)));
  sourceTab.click();
}
 
Example 16
Source File: SeleniumCheck.java    From phoenix.webui.framework with Apache License 2.0 4 votes vote down vote up
@Override
public void checkByValue(Element element, String value)
{
	WebElement parentWebEle = searchStrategyUtils.findStrategy(WebElement.class, element).search(element);
	if(parentWebEle == null)
	{
		logger.error(String.format("can not found element byText [%s].", value));
		return;
	}
	
	List<Locator> locatorList = element.getLocatorList();
	List<Locator> tmpList = new ArrayList<Locator>(locatorList);
	
	ElementSearchStrategy<WebElement> strategy = context.getBean("zoneSearchStrategy", ElementSearchStrategy.class);
	
	SeleniumValueLocator valueLocator = context.getBean(SeleniumValueLocator.class);
	valueLocator.setHostType("byTagName");
	valueLocator.setHostValue("input");
	
	locatorList.clear();
	locatorList.add(valueLocator);
	valueLocator.setValue(value);
	
	WebElement itemWebEle = null;
	try
	{
		if(strategy instanceof ParentElement)
		{
			((ParentElement) strategy).setParent(parentWebEle);
		}
		
		itemWebEle = strategy.search(element);
		if(itemWebEle != null)
		{
			if(!itemWebEle.isSelected())
			{
				itemWebEle.click();
			}
		}
	}
	catch(ElementNotVisibleException e)
	{
		e.printStackTrace();
		logger.error(String.format("Element [%s] click error, parent [%s], text [%s].",
				itemWebEle, element, value));
	}
	finally
	{
		//清空缓存
		locatorList.clear();
		locatorList.addAll(tmpList);
		
		if(strategy instanceof ParentElement)
		{
			((ParentElement) strategy).setParent(null);
		}
	}
}
 
Example 17
Source File: AsyncDemoIT.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Test
public void testAsyncDemo() {
   navigateToPage("Async Tests");
   waitingAsserter.waitFor(visibilityOfElementLocated(By.xpath(REQUEST_RECIEVED_XPATH)));

   for (Boolean recursive : unmodifiableList(Boolean.FALSE, Boolean.TRUE)) {
      sendKeysToElement(driver, waitingAsserter, getXpath("input", "AsyncPortlet", "delay"), "1");

      int reps = 1;

      if (recursive) {
         clickElement(driver, waitingAsserter, "//input[@name='auto'][@type='checkbox']");
         sendKeysToElement(driver, waitingAsserter, getXpath("input", "AsyncPortlet", "reps"),
               Integer.toString(reps));
      }

      List<WebElement> timeoutRadioButtons = driver.findElements(By.xpath("//input[@name='toType']"));

      for (int i = 0; i < timeoutRadioButtons.size(); i++) {

         timeoutRadioButtons = driver.findElements(By.xpath("//input[@name='toType']"));
         timeoutRadioButtons.get(i).click();

         List<WebElement> typeRadioButtons = driver.findElements(By.xpath("//input[@name='type']"));

         for (int j = 0; j < typeRadioButtons.size(); j++) {

            typeRadioButtons = driver.findElements(By.xpath("//input[@name='type']"));
            typeRadioButtons.get(j).click();

            String showFilterCheckboxByXpath = "//input[@name='filter'][@type='checkbox']";
            waitingAsserter.waitFor(visibilityOfElementLocated(By.xpath(showFilterCheckboxByXpath)));
            WebElement showFilterCheckbox =
                  driver.findElement(By.xpath(showFilterCheckboxByXpath));

            if (!isChecked(showFilterCheckboxByXpath)) {
               showFilterCheckbox.click();
            }

            String showListenerCheckboxXpath = "//input[@name='listener'][@type='checkbox']";

            if (!isChecked(showListenerCheckboxXpath)) {
               clickElement(driver, waitingAsserter, showListenerCheckboxXpath);
            }

            clickElement(driver, waitingAsserter, getXpath("input", "AsyncPortlet", "send") +
                  "[@value='execute']");

            for (int r = 1; r <= reps; r++) {

               if (isChecked(showFilterCheckboxByXpath)) {
                  assertMessageVisisble("msgbox", "REQUEST", "[contains(text(),'Filter:')]");

                  if (!recursive) {
                     assertMessageVisisble("msgbox", "ASYNC", "[contains(text(),'Filter:')]");
                  }
               }

               if (isChecked(showListenerCheckboxXpath) && !recursive) {
                  assertMessageVisisble("orangebox", "ASYNC", "[contains(.,'Listener: restarting async.')]");
               }
               
               waitingAsserter.waitFor(visibilityOfElementLocated(By.xpath(REQUEST_RECIEVED_XPATH +
                     "[" + r + "]")));
            }
         }
      }
   }
}
 
Example 18
Source File: JavaScriptHelper.java    From SeleniumCucumber with GNU General Public License v3.0 4 votes vote down vote up
public void scrollToElemetAndClick(WebElement element) {
	scrollToElemet(element);
	element.click();
	oLog.info(element);
}
 
Example 19
Source File: CheckBoxOrRadioButtonHelper.java    From SeleniumCucumber with GNU General Public License v3.0 4 votes vote down vote up
public void selectCheckBox(WebElement element) {
	if(!isIselected(element))
		element.click();
	oLog.info(element);
}
 
Example 20
Source File: UIUtils.java    From keycloak with Apache License 2.0 2 votes vote down vote up
/**
 * This is as an alternative for {@link #clickLink(WebElement)} and should be used in situations where we can't use
 * {@link WaitUtils#waitForPageToLoad()}. This is because {@link WaitUtils#waitForPageToLoad()} would wait until the
 * alert would disappeared itself (timeout).
 *
 * @param button to click on
 */
public static void clickBtnAndWaitForAlert(WebElement button) {
    button.click();
    AbstractPatternFlyAlert.waitUntilDisplayed();
}