SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

Actions keyDown do not work when combining them with click (simulate CTRL+click or SHIFT+click) #6817

Open lukeis opened 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 6817

You can use this code (java) to reproduce the problem:

WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.internetExplorer());
driver = new Augmenter().augment(driver);       
driver.navigate().to("http://fiddle.jshell.net/g8Rpe/show/");

List<WebElement> text = driver.findElements(By.cssSelector("tr"));

Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL)
       .click(text.get(1))
       .click(text.get(3))
       .click(text.get(4))
       .keyUp(Keys.CONTROL)
       .perform();

What is the expected output? What do you see instead?
- I expect 3 rows to be selected (see attached screenshot), but it looks like the keyDown(Keys.CONTROL)
is released when the click() is called...

Selenium version: 2.39.0
OS: Win 7
Browser: IE
Browser version: 11.0.2

I've tried the same with the Robot java class and this works locally:

Robot robot;
try {
    robot = new Robot();
    robot.keyPress(KeyEvent.VK_CONTROL);
    text.get(1).click();
    text.get(3).click();
    text.get(4).click();
    robot.keyRelease(KeyEvent.VK_CONTROL);
} catch (Exception e) {
    e.printStackTrace();
}

But this is a bad workaround since the Robot class does not work when using the Selenium
Grid. I've also searched for this problem and it looks like it is known for quite a
while but it still isn't fixed :(

Reported by ruud@vdbstudios.be on 2014-01-09 08:42:52


lukeis commented 8 years ago

Reported by barancev on 2014-01-09 12:34:35

lukeis commented 8 years ago
Same problem in BUG http://code.google.com/p/selenium/issues/detail?id=4385 (reported:
August 2012)

I've provided a full reproducible example, I hope this issue can be solved now.

Reported by ruud@vdbstudios.be on 2014-01-13 07:29:36

lukeis commented 8 years ago
Same problem also in BUG http://code.google.com/p/selenium/issues/detail?id=6280 (reported:
September 2013)

I've also tried with Firefox 26:

FirefoxProfile p = new FirefoxProfile();
p.setEnableNativeEvents(false);

DesiredCapabilities d = new DesiredCapabilities();
d.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
d.setCapability(FirefoxDriver.PROFILE, p);

WebDriver driver;
driver = new RemoteWebDriver("http://127.0.0.1:4444/wd/hub d);
driver = new Augmenter().augment(driver);

=> This works (if you disable the native events)... But we need it in IE :)

Reported by ruud@vdbstudios.be on 2014-01-13 07:58:37

lukeis commented 8 years ago
This also works in IE:

DesiredCapabilities d;
d = DesiredCapabilities.internetExplorer();
d.setCapability("requireWindowFocus", true);

WebDriver driver;
driver = new RemoteWebDriver("http://127.0.0.1:4444/wd/hub", d);
driver = new Augmenter().augment(driver);

=> I guess setting the requireWindowFocus capability will disable native events? 

Reported by ruud@vdbstudios.be on 2014-01-13 08:27:13

lukeis commented 8 years ago
This also doesn't work when the capability 'requireWindowFocus' is set to false:

WebElement el = driver.findElementsBy(By.cssSelector("div"));
Actions actions = new Actions(driver);
actions.moveToElement(el).clickAndHold().moveByOffset(100, 100).release().perform();

Reported by ruud@vdbstudios.be on 2014-01-22 14:23:00

lukeis commented 8 years ago
Same problem with version 2.40

Reported by ruud@vdbstudios.be on 2014-02-26 10:30:58

lukeis commented 8 years ago
I believe that this is a related issue: http://code.google.com/p/selenium/issues/detail?id=4973

I was about to file comments there but since `requireWindowFocus` affect the results
I get, I'm going to call the two issues equal and file here instead.

=====

*** Versions

Selenium version client-side: 2.40.0
Selenium version server-side: 2.39.0
OS: Debian testing up to date as of 2014-03-18
Browser: IE
Browser version: 9, 10, 11

** What steps will reproduce the problem?

1. Download the `selenium_bug.py` file.

2. Edit it so that it starts IE. I have to use Sauce Labs because I
am not set to run IE 11 (or any other version of IE) here.

3. Run the script.

The script outputs whether or not events are native.

Then it performs 3 tests:

a. It types the string "abc", Keys.SHIFT, Keys.ARROW_LEFT twice,
   Keys.SHIFT, and the string "x". This test uses
   `ActionChains.send_keys_to_element` and uses the `#first` field.

   It outputs the final value of the field to stdout.

b. It clicks the `#second` field and types the same thing as the first test
   but uses `ActionChains.send_keys`.

   It outputs the final value of the field to stdout.

c. It types the Keys.SHIFT, the string "abc", and Keys.SHIFT,
   using `ActionChains.send_keys_to_element` and uses the `#third` field.

   It outputs the final value of the field to stdout.

Finally, it dumps the global variable `records` to the screen. This
variable contains results recorded by a `keydown` listener on the
fields. Each time a key is pressed the state of the `shiftKey` field
on the event is recorded. The `records` variable is structured so that
each key is the name of the field ("first", "second" and "third") and
the associated value is the list of `shiftKey` states recorded
whenever a key was pressed in the field.

** What is the expected output?

I get the following output on Chrome and Firefox on my Debian system
and when I run them on Windows through Sauce Labs.

native:  True
ax
ax
ABC
first [False, False, False, False, True, True, False]
second [False, False, False, False, True, True, False, False]
third [True, True, True, False]

** What do you see instead?

If `requireWindowFocus` is true:

native:  True
ax
ax
ABC
first [False, False, False, True, True, True, False]
second [False, False, False, True, True, True, False, True]
third [True, True, True, True]

If `requireWindowFocus` is false:

native:  True
ax
ax
ABC
first [False, False, False, False, False, False, False]
second [False, False, False, False, False, False, False, False]
third [False, False, False, False]

** Observations

Could Sauce Labs be the problem? I think not, since if I run the
script with Firefox or Chrome on Sauce Labs, the scripts performs as
expected.

The values of the fields which are output to the screen show that from
the perspective of someone just looking at the fields, it appears that
Selenium is sending the correct events. It is only the JavaScript
which is not receiving events with `shiftKey` set to the proper value.

`requireWindowFocus` helps but it is not a complete
workaround. Consider the output of the second test when using IE:

second [False, False, False, True, True, True, False, True]

The last item in the list is an extra event emitted by
Selenium. However, when using `send_keys_to_element` like in the first
test, the sequence is better:

first [False, False, False, True, True, True, False]

I am not calling it "correct" because I'd want to see exactly the same
sequence as for Chrome and Firefox.

Reported by avaktavyam on 2014-03-18 15:40:07


lukeis commented 8 years ago
More than a year later and still nog update? 

Reported by ruud@vdbstudios.be on 2015-09-14 08:49:47

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 17:46:32