I'm working with Geb on automating testing of a web application that uses ExtJS to present much of its UI. I'm in a situation where I need to ctrl-click several ExtJS-generated table cells representing 'categories'. How do I use Geb to ctrl-click these things?
Asked
Active
Viewed 1,570 times
1 Answers
3
To do control-clicking I had to access a WebDriver WebElement object directly using firstElement:
def categoryItem = $("div.category-item-title", text: categoryName).firstElement()
Then the Actions object can be used to add control-click actions:
Actions actions = new Actions(driver)
actions = actions.keyDown(Keys.CONTROL)
actions = actions.click(categoryItem)
actions = actions.keyUp(Keys.CONTROL)
actions.perform()
Note this code is within an instance method of a page object.
Here is the same code using the 'interact' mechanism erdi mentioned:
interact {
keyDown(Keys.CONTROL)
click($("div.category-item-title", text: categoryName))
keyUp(Keys.CONTROL)
}

Ian Durkan
- 1,212
- 1
- 12
- 26
-
1Please note that Geb aids you in making your proposed solution even simpler - check out manual section about [interact closure](http://www.gebish.org/manual/current/navigator.html#drag_and_drop) – erdi Jan 02 '13 at 17:42
-
Moving that documentation so it's not hidden under section "drag and drop" could help save others' time. – Ian Durkan Jan 03 '13 at 21:01
-
Thanks for the suggestion, we already have a ticket for that: http://jira.codehaus.org/browse/GEB-207 – erdi Jan 08 '13 at 13:12