Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control-click items using Geb?

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?

like image 717
Ian Durkan Avatar asked Oct 21 '22 20:10

Ian Durkan


1 Answers

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)
}
like image 192
Ian Durkan Avatar answered Nov 01 '22 07:11

Ian Durkan