我有这行代码:
final WebElement button = driver.findElement(By.tagName("button"));
现在,如何在按住元键的情况下点击该按钮?
答案 0 :(得分:11)
嗯..我不太确定java,但在C#中这是用ActionBuilder完成的 -
new Actions(Browser).KeyDown(Keys.Shift).Click(element).KeyUp(Keys.Shift).Perform();
答案 1 :(得分:9)
根据Madd0g,java代码看起来像这样:
Actions shiftClick = new Actions(driver);
shiftClick.keyDown(Keys.SHIFT).click(element).keyUp(Keys.SHIFT).perform();
答案 2 :(得分:2)
找到它。 http://code.google.com/p/selenium/wiki/AdvancedUserInteractions
final WebElement button = driver.findElement(By.id("button"));
Actions actions = new Actions(driver);
if (ctrlKey) {
actions = actions.keyDown(Keys.CONTROL);
}
if (altKey) {
actions = actions.keyDown(Keys.ALT);
}
if (shiftKey) {
actions = actions.keyDown(Keys.SHIFT);
}
actions = actions.click(button);
现在,只要它确实有效。