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


Java Keys类代码示例

本文整理汇总了Java中org.openqa.selenium.Keys的典型用法代码示例。如果您正苦于以下问题:Java Keys类的具体用法?Java Keys怎么用?Java Keys使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: searchFor

import org.openqa.selenium.Keys; //导入依赖的package包/类
/**
 * Types into the search bar in the top right and searches.
 * 
 * @param content
 *            - The value to type into the search bar.
 */
public void searchFor(String content) {
	this.focusForm(false);
	WebElement mGTypeArea = _wait.until(ExpectedConditions.presenceOfElementLocated(By.name("sysparm_search")));
	if (!mGTypeArea.getClass().toString().contains("focus")) {
		WebElement magnifyingGlass = _wait
				.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("[action='textsearch.do']")));
		magnifyingGlass.click();
	}
	if(!mGTypeArea.getAttribute("value").equalsIgnoreCase("")) {
		mGTypeArea.clear();
	}
	mGTypeArea.sendKeys(content);
	mGTypeArea.sendKeys(Keys.ENTER);
}
 
开发者ID:SeanABoyer,项目名称:ServiceNow_Selenium,代码行数:21,代码来源:ServiceNow.java

示例2: putText

import org.openqa.selenium.Keys; //导入依赖的package包/类
@Override
public boolean putText(WebElement w, String... args) throws Exception{
	boolean result = false;
	String d = args[0];
	boolean includesReturn = false;
	if(d.indexOf("\\n") > -1 || d.indexOf("\\r") > -1){
		d = d.replace("\\n", "");
		d = d.replace("\\r", "");
		includesReturn = true;
	}
	try{
		w.clear();
		w.sendKeys(d);
		if(includesReturn){
			w.sendKeys(Keys.RETURN);
		}
		result = true;
	}catch(Exception e){
		e.printStackTrace();
		result = false;
	}
	Assert.assertTrue(result, w.toString() + " insert text " + d);
	return result;
}
 
开发者ID:saiscode,项目名称:kheera,代码行数:25,代码来源:AbstractPage.java

示例3: sendKeys

import org.openqa.selenium.Keys; //导入依赖的package包/类
@Test(enabled = false) public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> scrollBars = driver.findElements(By.cssSelector("scroll-bar"));
    WebElement scrollbar = scrollBars.get(0);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_DOWN);
    AssertJUnit.assertEquals("28", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_UP);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));

    scrollbar = scrollBars.get(1);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_RIGHT);
    AssertJUnit.assertEquals("28", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_LEFT);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:JScrollBarTest.java

示例4: sendKeys

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    WebElement textArea = driver.findElement(By.cssSelector("text-area"));
    AssertJUnit.assertEquals("true", textArea.getAttribute("editable"));
    textArea.clear();
    AssertJUnit.assertEquals("", textArea.getText());
    textArea.sendKeys("Lewis CarrollR");
    textArea.sendKeys(Keys.BACK_SPACE);
    AssertJUnit.assertEquals("Lewis Carroll", textArea.getText());
    textArea.sendKeys(Keys.HOME + "Jhon ");
    AssertJUnit.assertEquals("Jhon Lewis Carroll", textArea.getText());
    for (int i = 0; i < 5; i++) {
        textArea.sendKeys(OSUtils.getKeysFor(textArea, "select-all"), OSUtils.getKeysFor(textArea, "copy-to-clipboard"),
                OSUtils.getKeysFor(textArea, "paste-from-clipboard"), Keys.END,
                OSUtils.getKeysFor(textArea, "paste-from-clipboard"));
    }
    textArea.sendKeys(OSUtils.getKeysFor(textArea, "select-all"));
    textArea.sendKeys(Keys.DELETE);
    AssertJUnit.assertEquals("", textArea.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:21,代码来源:JTextAreaTest.java

示例5: checkAltRightClickEvent

import org.openqa.selenium.Keys; //导入依赖的package包/类
private void checkAltRightClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    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);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).keyDown(Keys.ALT).contextClick().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
    // Wait till the previous click is processed by the EDT
    Thread.sleep(500);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:40,代码来源:NativeEventsTest.java

示例6: enteredGeneratesSameEvents

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    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);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:39,代码来源:NativeEventsTest.java

示例7: sendKeys

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> checkBoxes = driver.findElements(By.cssSelector("check-box"));
    AssertJUnit.assertEquals(4, checkBoxes.size());
    WebElement chkbox1 = checkBoxes.get(0);
    AssertJUnit.assertEquals("Chin", chkbox1.getAttribute("buttonText"));
    WebElement chkbox2 = checkBoxes.get(1);
    AssertJUnit.assertEquals("Glasses", chkbox2.getAttribute("buttonText"));
    WebElement chkbox3 = checkBoxes.get(2);
    AssertJUnit.assertEquals("Hair", chkbox3.getAttribute("buttonText"));
    WebElement chkbox4 = checkBoxes.get(3);
    AssertJUnit.assertEquals("Teeth", chkbox4.getAttribute("buttonText"));

    AssertJUnit.assertEquals("true", chkbox1.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox2.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox3.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox4.getAttribute("selected"));
    chkbox3.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("true", chkbox1.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox2.getAttribute("selected"));
    AssertJUnit.assertEquals("false", chkbox3.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox4.getAttribute("selected"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:24,代码来源:JCheckBoxTest.java

示例8: editANodeWithEditor

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void editANodeWithEditor() throws Throwable {
    System.err.println("Ignore the following NPE. The DynamicTree class has a bug");
    WebElement tree = page.getTree();
    tree.click();
    final WebElement root = tree.findElement(By.cssSelector(".::root"));
    AssertJUnit.assertEquals("Root Node", root.getText());
    WebElement editor = root.findElement(By.cssSelector(".::editor"));
    editor.clear();
    editor.sendKeys("Hello World", Keys.ENTER);
    root.submit();
    new WebDriverWait(driver, 3).until(new Function<WebDriver, Boolean>() {
        @Override public Boolean apply(WebDriver input) {
            return root.getText().equals("Hello World");
        }
    });
    AssertJUnit.assertEquals("Hello World", root.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:JTreeDynamicTreeTest.java

示例9: login

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void login() throws Throwable {
    driver = new JavaDriver();
    WebElement passField = driver.findElement(By.cssSelector("password-field"));
    AssertJUnit.assertEquals("true", passField.getAttribute("enabled"));
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
    passField.sendKeys("password");
    WebElement button = driver.findElement(By.cssSelector("button"));
    button.click();
    driver.switchTo().window("Error Message");
    WebElement label = driver.findElement(By.cssSelector("label[text*='Invalid']"));
    AssertJUnit.assertEquals("Invalid password. Try again.", label.getText());
    WebElement button1 = driver.findElement(By.cssSelector("button"));
    button1.click();
    driver.switchTo().window("JPasswordFieldTest");
    passField.clear();
    passField.sendKeys("bugaboo", Keys.ENTER);
    driver.switchTo().window("Message");
    WebElement label2 = driver.findElement(By.cssSelector("label[text*='Success']"));
    AssertJUnit.assertEquals("Success! You typed the right password.", label2.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:22,代码来源:JPasswordFieldTest.java

示例10: listMultipleSelectWithControl

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void listMultipleSelectWithControl() throws Throwable {
    driver = new JavaDriver();

    WebElement pickNameButton = driver.findElement(By.cssSelector("button"));
    AssertJUnit.assertEquals("Pick a new name...", pickNameButton.getText());
    pickNameButton.click();

    WebDriver nameChooserWindow = driver.switchTo().window("Name Chooser");
    AssertJUnit.assertEquals("Name Chooser", nameChooserWindow.getTitle());

    List<WebElement> list = driver.findElements(By.cssSelector("list"));
    AssertJUnit.assertEquals(1, list.size());

    List<WebElement> listItems;
    listItems = driver.findElements(By.cssSelector("list::all-items"));
    AssertJUnit.assertEquals(12, listItems.size());

    WebElement listItem;
    listItem = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listItem2 = driver.findElement(By.cssSelector("list::nth-item(3)"));
    new Actions(driver).click(listItem).sendKeys(Keys.COMMAND).click(listItem2).sendKeys(Keys.COMMAND).perform();
    AssertJUnit.assertEquals("[2]", list.get(0).getAttribute("selectedIndices"));
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    buttons.get(1).click();
    Thread.sleep(1000);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:27,代码来源:JListRunnerTest.java

示例11: dndWithCopy

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.isWindows()) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:25,代码来源:DragAndDropTest.java

示例12: sendKeys

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    AssertJUnit.assertEquals(3, buttons.size());
    WebElement b1 = buttons.get(0);
    AssertJUnit.assertEquals("Disable middle button", b1.getText());
    WebElement b2 = buttons.get(1);
    AssertJUnit.assertEquals("Middle button", b2.getText());
    WebElement b3 = buttons.get(2);
    AssertJUnit.assertEquals("Enable middle button", b3.getText());
    AssertJUnit.assertEquals("true", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b3.getAttribute("enabled"));
    b1.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("false", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b3.getAttribute("enabled"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JButtonTest.java

示例13: sendKeys

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    AssertJUnit.assertEquals(3, buttons.size());
    WebElement b1 = buttons.get(0);
    AssertJUnit.assertEquals("<html><center><b><u>D</u>isable</b><br><font color=#ffffdd>middle button</font>", b1.getText());
    WebElement b2 = buttons.get(1);
    AssertJUnit.assertEquals("middle button", b2.getText());
    WebElement b3 = buttons.get(2);
    AssertJUnit.assertEquals("<html><center><b><u>E</u>nable</b><br><font color=#ffffdd>middle button</font>", b3.getText());
    AssertJUnit.assertEquals("true", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b3.getAttribute("enabled"));
    b1.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("false", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b3.getAttribute("enabled"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JButtonHtmlTest.java

示例14: sendKeys

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> textfields = driver.findElements(By.cssSelector("formatted-text-field"));
    WebElement tf = textfields.get(0);
    WebElement other = textfields.get(1);
    AssertJUnit.assertEquals("100,000", tf.getText());
    AssertJUnit.assertEquals("100000.0", tf.getAttribute("value"));
    tf.sendKeys(Keys.chord(Keys.SHIFT, Keys.END), "1234");
    AssertJUnit.assertEquals("1234", tf.getText());
    other.click();
    AssertJUnit.assertEquals("1234", tf.getAttribute("value"));
    AssertJUnit.assertEquals("1,234", tf.getText());

    tf = textfields.get(2);
    AssertJUnit.assertEquals("30", tf.getText());
    tf.sendKeys(Keys.chord(Keys.SHIFT, Keys.END), Keys.DELETE);
    AssertJUnit.assertEquals("", tf.getText());
    tf.sendKeys("123");
    AssertJUnit.assertEquals("123", tf.getText());
    other.click();
    AssertJUnit.assertEquals("123", tf.getAttribute("value"));

}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:24,代码来源:JFormattedTextFieldTest.java

示例15: getCellEditor

import org.openqa.selenium.Keys; //导入依赖的package包/类
public void getCellEditor() throws Throwable {
    driver = new JavaDriver();
    WebElement cell = driver.findElement(By.cssSelector("table::mnth-cell(1,2)::editor"));
    AssertJUnit.assertEquals("button", cell.getTagName());
    cell.click();
    driver.switchTo().window("Pick a Color");
    WebElement tab = driver.findElement(By.cssSelector("tabbed-pane::all-tabs[text='RGB']"));
    tab.click();
    WebElement tabcomponent = driver.findElement(By.cssSelector("tabbed-pane::all-tabs[text='RGB']::component"));
    List<WebElement> spinners = tabcomponent.findElements(By.cssSelector("spinner"));
    List<WebElement> all = spinners.get(0).findElements(By.cssSelector("*"));
    List<String> s = new ArrayList<String>();
    for (WebElement webElement : all) {
        s.add(webElement.getTagName());
    }
    WebElement tf = spinners.get(0).findElement(By.cssSelector("formatted-text-field"));
    tf.clear();
    tf.sendKeys("234", Keys.TAB);
    driver.findElement(By.cssSelector("button[text='OK']")).click();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:21,代码来源:JTableDialogEditTest.java


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