multiple select with Actions class

439 views
Skip to first unread message

Anupam Patil

unread,
Dec 18, 2015, 2:19:15 AM12/18/15
to Selenium Users
I tried to select multiple select value using Actions class with Control Key. It's not selecting multiple element,instead it is selecting only one. How to select multiple values with Actions class? Why the program is behaving like that?

Note:- It can be easily achieved by in-built Select class.

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class select_with_control_key {
public static void main(String[] args) {
WebDriver d=new FirefoxDriver();
d.get("http://toolsqa.com/automation-practice-form/");
Actions actions = new Actions(d);
actions.keyDown(Keys.CONTROL)
.click(d.findElement(By.xpath("//option[text()='Wait Commands']")))
.click(d.findElement(By.xpath("//option[text()='Navigation Commands']")))
.keyUp(Keys.CONTROL)
.build()
.perform();

}
}

Capture.PNG

Xiang Dong

unread,
Dec 18, 2015, 8:40:18 AM12/18/15
to seleniu...@googlegroups.com
following codes may help you:

                        Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
try {

for (WebElement webElement : allWebElements) {
webElement.click();
}
} finally {
robot.keyRelease(KeyEvent.VK_CONTROL); 
                       }
It is java code.

Best Regards,
--david


Date: Thu, 17 Dec 2015 23:19:14 -0800
From: anup...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] multiple select with Actions class
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c5d0cb46-1d01-40f2-a379-6c163a4ebde4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Xiang Dong

unread,
Dec 18, 2015, 8:41:47 AM12/18/15
to seleniu...@googlegroups.com
For Chrome and Firefox:

Actions action = new Actions(webDriver);
action.keyDown(Keys.CONTROL);
for (WebElement webElement : allWebElements) {
action.moveToElement(webElement).click(webElement);
}
action.keyUp(Keys.CONTROL);
action.build().perform();


Date: Thu, 17 Dec 2015 23:19:14 -0800
From: anup...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] multiple select with Actions class

Reply all
Reply to author
Forward
0 new messages