當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。