当前位置: 首页>>代码示例>>Java>>正文


Java WebElement.click方法代码示例

本文整理汇总了Java中org.openqa.selenium.WebElement.click方法的典型用法代码示例。如果您正苦于以下问题:Java WebElement.click方法的具体用法?Java WebElement.click怎么用?Java WebElement.click使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openqa.selenium.WebElement的用法示例。


在下文中一共展示了WebElement.click方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: draggedGeneratesSameEvents

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void draggedGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_DRAGGED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");

    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    tclear();
    System.err.println("============================");
    new Actions(driver).clickAndHold(b).moveToElement(b).release().perform();
    System.err.println("============================");
    AssertJUnit.assertEquals(expected, t.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:41,代码来源:NativeEventsTest.java

示例2: addInformationTypeField

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void addInformationTypeField() {
    // get element
    WebElement addButton = helper.findElement(By.xpath(ROOT_ELEMENT_XPATH + "//a[contains(@class, 'add-link')]"));

    // scroll to element, to prevent errors like "Other element would receive the click"
    new Actions(webDriver)
        .moveToElement(addButton)
        .moveByOffset(0, 200)
        .perform();

    // click
    addButton.click();

    // wait after click for the dropdown to appear
    helper.findElement(By.xpath(DROPDOWN_XPATH));
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:17,代码来源:InformationTypeCmsWidget.java

示例3: checkAllCheckBoxes

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Action(object = ObjectType.BROWSER, desc = "Check all the check boxes in the context")
public void checkAllCheckBoxes() {
    try {
        List<WebElement> checkboxes = Driver.findElements(By.cssSelector("input[type=checkbox]"));
        if (checkboxes.isEmpty()) {
            Report.updateTestLog(Action, "No Checkbox present in the page", Status.WARNING);
        } else {
            for (WebElement checkbox : checkboxes) {
                if (checkbox.isDisplayed() && !checkbox.isSelected()) {
                    checkbox.click();
                }
            }
            Report.updateTestLog(Action, "All checkboxes are checked", Status.PASS);
        }
    } catch (Exception ex) {
        Report.updateTestLog(Action, "Error while checking checkboxes - " + ex, Status.FAIL);
        Logger.getLogger(CheckBox.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:20,代码来源:CheckBox.java

示例4: expandTree

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void expandTree() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals("false", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(root, "expanded", "true"));
    AssertJUnit.assertEquals("true", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
    WebElement node1 = tree.findElement(By.cssSelector(".::nth-node(2)"));
    AssertJUnit.assertEquals("Parent 1", node1.getText());
    new Actions(driver).doubleClick(node1).perform();
    WebElement node2 = tree.findElement(By.cssSelector(".::nth-node(3)"));
    AssertJUnit.assertEquals("Child 1", node2.getText());
    WebElement node3 = tree.findElement(By.cssSelector(".::nth-node(4)"));
    AssertJUnit.assertEquals("Child 2", node3.getText());
    WebElement node4 = tree.findElement(By.cssSelector(".::nth-node(5)"));
    AssertJUnit.assertEquals("Parent 2", node4.getText());
    new Actions(driver).doubleClick(node4).perform();
    WebElement node5 = tree.findElement(By.cssSelector(".::nth-node(6)"));
    AssertJUnit.assertEquals("Child 1", node5.getText());
    WebElement node6 = tree.findElement(By.cssSelector(".::nth-node(7)"));
    AssertJUnit.assertEquals("Child 2", node6.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:26,代码来源:JTreeDynamicTreeTest.java

示例5: typeInElement

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * @category Set Element
 */
private void typeInElement(WebElement element, String content) {
	_action.moveToElement(element);
	switch (this.getFieldType(element)) {
	case "choice":
		List<WebElement> options = element.findElements(By.tagName("option"));
		for (int i = 0; i < options.size(); i++) {
			if (options.get(i).getText().trim().equalsIgnoreCase(content)) {
				element.click();
				options.get(i).click();
				break;
			}
		}
		break;
	default:
		_action.click();
		if(!this.getFieldValueByID(element.getAttribute("id")).equalsIgnoreCase("")) {
			//TODO - Find a faster way to do this.
			_action.sendKeys(Keys.END);
			for (int i = 0; i <this.getFieldValueByID(element.getAttribute("id")).length(); i ++) {
				_action.sendKeys(Keys.BACK_SPACE);
			}

		}
		_action.sendKeys(content);
		_action.sendKeys(Keys.TAB);
	_action.perform();
	}

}
 
开发者ID:SeanABoyer,项目名称:ServiceNow_Selenium,代码行数:33,代码来源:ServiceNow.java

示例6: selectSemester

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
private void selectSemester() {
    final WebElement selectElement = driver.findElement(By.id("lbWeeks"));
    for (WebElement option : selectElement.findElements(By.tagName("option"))) {
        if (option.getText().toLowerCase().contains("semester")) {
            option.click();
            return;
        }
    }
}
 
开发者ID:gandreadis,项目名称:vu-timetable,代码行数:10,代码来源:Navigator.java

示例7: selectByLabel

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void selectByLabel(String label)
{
    WebElement element = element();

    element.click();
    element.sendKeys(label);
    element.sendKeys(Keys.RETURN);
}
 
开发者ID:porscheinformatik,项目名称:selenium-components,代码行数:9,代码来源:SelectComponent.java

示例8: positionateAndClick

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Positionate in an element naturally (scrolling and clicking)
 * @param webElement Element
 * @return Element
 * @throws Exception
 */
public WebElement positionateAndClick(WebElement element) throws Exception {
    Actions mouseActions = new Actions(driver);
    try {
        mouseActions.moveToElement(element).build().perform();
        mouseActions.click(element).build().perform();
    } catch (Exception e) {
        //not moveable
        element.click();
    }
    
    return element;
}
 
开发者ID:brunocvcunha,项目名称:seleneasy,代码行数:19,代码来源:Seleneasy.java

示例9: nodeEditor

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void nodeEditor() throws Throwable {
    System.err.println("Ignore the following NPE. The DynamicTree class has a bug");
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals("Root Node", root.getText());
    WebElement editor = root.findElement(By.cssSelector(".::editor"));
    editor.clear();
    editor.sendKeys("Hello World", Keys.ENTER);
    root.submit();
    AssertJUnit.assertEquals("Hello World", root.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:JTreeDynamicTreeTest.java

示例10: click

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * 点击元素
 * 
 * @param element
 */
public void click(WebElement element) {
	try {
		element.click();
		LogUtil.debug(getDriver().manage().logs() + "==>" + element.toString() + " 点击成功!");
	} catch (Exception e) {
		LogUtil.error(getDriver().manage().logs() + "==>" + element.toString() + " 点击失败!" + e);
		screenShot();
		AssertUtil.fail(getDriver().manage().logs() + "==>" + element.toString() + " 点击失败!" + e);
	}
}
 
开发者ID:quanqinle,项目名称:WebAndAppUITesting,代码行数:16,代码来源:BaseOpt.java

示例11: testWithAndroid

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Test
void testWithAndroid(AppiumDriver<MobileElement> driver)
        throws InterruptedException {
    WebElement button = driver.findElement(By.id("buttonStartWebview"));
    button.click();

    WebElement inputField = driver.findElement(By.id("name_input"));
    inputField.clear();
    inputField.sendKeys("Custom name");
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:11,代码来源:AppiumApkJupiterTest.java

示例12: setShowOnlyOwnCountry

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void setShowOnlyOwnCountry(boolean value) {

        List<WebElement> elements = driver.findElements(By.id("showOnlyOwnCountryForm:showOnlyOwnCountry"));
        WebElement e = elements.get(0);

        if ((value && !e.isSelected()) || (!value && e.isSelected())) {
            e.click();
            waitForPageToLoad();
        }
    }
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:11,代码来源:HomePageObject.java

示例13: MenuOverview

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Test
public void MenuOverview(){
	WebDriverWait wait = new WebDriverWait(driver, 10);
	WebElement menuButton = driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"Open navigation\"]"));

	menuButton.click();
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Overview\"]"))));

    WebElement overViewButton = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Overview\"]"))));
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Accounts\"]"))));
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Transactions\"]"))));
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Reports\"]"))));
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@text=\"Settings\"]"))));
    overViewButton.click();
}
 
开发者ID:ark-konopacki,项目名称:appium_tutorial,代码行数:16,代码来源:AndroidTest.java

示例14: main

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  // Create a DesiredCapabilities object to request specific devices from the WebDriver server.
  // A udid can be optionally specified, otherwise an arbitrary device is chosen.
  DesiredCapabilities caps = new DesiredCapabilities();
  // caps.setCapability("uuid", udid);
  // Start a WebDriver session. The local machine has to be running the SafariDriverServer, or
  // change localhost below to an IP running the SafariDriverServer.
  driver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), caps);
  // Connect to a URL
  driver.get("http://www.google.com");

  // Interact with the web page. In this example use case, the Webdriver API is used to find
  // specific elements, test a google search and take a screenshot.
  driver.findElement(By.id("hplogo"));

  // Google New York
  WebElement mobileSearchBox = driver.findElement(By.id("lst-ib"));
  mobileSearchBox.sendKeys("New York");
  WebElement searchBox;
  try {
    searchBox = driver.findElement(By.id("tsbb"));
  } catch (NoSuchElementException e) {
    searchBox = driver.findElement(By.name("btnG"));
  }
  searchBox.click();

  takeScreenshot();
  driver.navigate().refresh();
  takeScreenshot();

  // Quit the WebDriver instance on completion of the test.
  driver.quit();
  driver = null;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:35,代码来源:ExampleMobileSafariWebTest.java

示例15: listClickingOnAnItemSelectsIt

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void listClickingOnAnItemSelectsIt() throws Throwable {
    EventQueueWait.waitTillShown(list);
    driver = new JavaDriver();
    WebElement listItem;
    listItem = driver.findElement(By.cssSelector("#list-1::nth-item(21)"));
    assertEquals("List Item - 21", listItem.getText());
    listItem.click();
    assertEquals("20", driver.findElement(By.cssSelector("#list-1")).getAttribute("selectedIndex"));
    listItem = driver.findElement(By.cssSelector("#list-1::nth-item(3)"));
    assertEquals("List Item - 3", listItem.getText());
    listItem.click();
    assertEquals("2", driver.findElement(By.cssSelector("#list-1")).getAttribute("selectedIndex"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JListXTest.java


注:本文中的org.openqa.selenium.WebElement.click方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。