Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key::TAB / postValue vs. Chrome 53 #243

Closed
lifeofguenter opened this issue Sep 2, 2016 · 22 comments
Closed

Key::TAB / postValue vs. Chrome 53 #243

lifeofguenter opened this issue Sep 2, 2016 · 22 comments

Comments

@lifeofguenter
Copy link

It seems that with recent Chrome (v53) Key::TAB as used in here: https://github.com/minkphp/MinkSelenium2Driver/blob/master/src/Selenium2Driver.php#L681 will actually cause the character \t to be added into the input-box, instead of "hitting the tab key".

I can not reproduce it on a normal workstation setup (e.g. real desktop), but it does not work on a headless chrome setup (Ubuntu 15.10 / selenium-server-standalone-2.53.1.jar):

$ google-chrome-stable --version
Google Chrome 53.0.2785.92
$ chromedriver --version
ChromeDriver 2.23.409687 (c46e862757edc04c06b1bd88724d15a5807b84d1)

Can be reproduced (headless-browser) with the following snippet:

<?php

ini_set('display_errors', true);
error_reporting(E_ALL);

require 'vendor/autoload.php';

$driver = new \Behat\Mink\Driver\Selenium2Driver('chrome');
$session = new \Behat\Mink\Session($driver);

$session->start();

$session->visit('http://localhost/admin/login');
sleep(2);
$session->getPage()->fillField('email', '[email protected]');
$session->getPage()->fillField('password', 'abcdef');
$session->getPage()->pressButton('login');

selenium-server is started like this:

screen -S selenium -d -m sh -c "DBUS_SESSION_BUS_ADDRESS=/dev/null xvfb-run -s '-screen 0 1024x768x24' -a java -jar /opt/selenium-server/selenium-server-standalone.jar > /home/bamboo/selenium.stdout.log 2> /home/bamboo/selenium.stderr.log"
$ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

Swapping out the browser from chrome to firefox (version 46.0.1) works, as well as removing that Key::TAB from the code above (however not sure if it is the right fix, as obviously it should be working?).

@aik099
Copy link
Member

aik099 commented Sep 3, 2016

  1. maybe this is bug in Selenium, that changes in Chrome (in way how TAB is handled) are not handled properly
  2. the TAB is sent to trigger onchange JS event

@lifeofguenter
Copy link
Author

Is this maybe related to: instaclick/php-webdriver#70 ?

@adridev
Copy link

adridev commented Sep 6, 2016

Facing the same issue here.

Google Chrome 53.0.2785.92

ChromeDriver 2.23.409687 (c46e862757edc04c06b1bd88724d15a5807b84d1)

Selenium server 2.53.1

@fonsecas72
Copy link

Did anyone found or confirmed anything?

@aik099
Copy link
Member

aik099 commented Sep 9, 2016

Me nope. Probably somebody needs to post an issue on Chrome Driver issue tracker (with a link to it posted back here).

@fonsecas72
Copy link

fonsecas72 commented Sep 9, 2016

ok, just for others to see, if I'm not mistaken, a workaround for findField could be something like this:

$xpath = $this->getSession()->getSelectorsHandler()->selectorToXpath('named', [
    'field',
    $locator
]);
$elementName = strtolower($this->getSession()->getDriver()->getTagName($xpath));
if ($elementName === 'input' || $elementName === 'textarea') {
    $element = $this->mink->getSession()->getDriver()->getWebDriverSession()->element('xpath', $xpath);
    $existingValueLength = strlen($element->attribute('value'));
    $value = str_repeat(Key::BACKSPACE.Key::DELETE, $existingValueLength).$value;
    $element->postValue(['value' => [$value]]);
} else {
    $this->findField($locator)->setValue($value);
}

@aik099
Copy link
Member

aik099 commented Sep 9, 2016

#243 (comment)

@fonsecas72 , you've just removed TAB if I'm reading this correctly. That is one of possible solutions, but then onchange event won't be fired in JavaScript when value is changed.

@fonsecas72
Copy link

yup, users should be aware of the downside when using it. I'd suggest to move it to a special method or something :)

@aik099 if you have a cleaner solution please let me know.

@adridev
Copy link

adridev commented Sep 9, 2016

for me, the workaround was to remove the Key::TAB from the end of the line in Selenium2Driver.php:662.

About the "change" event, I don't know if is correct to fire this event automatically when an input is filled. I think could be more natural to have to explicitly hit the enter or leave the field to fire this event.

@aik099
Copy link
Member

aik099 commented Sep 9, 2016

That change event firing also created problems for testing stuff, like jQueryUI.Autocomplete, because immediately after value change the dropdown with completions was hidden.

@stof , I know this might be a BC break, but maybe for inputs with free text entry (not checkbox/radio button/select) we can stop firing change JS event. If agreed, then we need a way to stop firing change event for other drivers as well.

@lifeofguenter
Copy link
Author

I think first we need to figure out if this is a BC break intended by chromedriver/chrome, or if it is actually a bug.

@doriancmore
Copy link
Contributor

How about this? doriancmore@e2710a2

@adridev
Copy link

adridev commented Sep 14, 2016

I'm making the same as a workaround but I not sure if is there the correct place for calling to excuteScript.

Probably is more natural to call the blur method after calling to setValue within the step definition. For example:

In \Behat\Mink\Element\TraversableElement:fillField

`
public function fillField($locator, $value)
{

//...

$field->setValue($value);
$field->blur();

}
`

@doriancmore
Copy link
Contributor

The idea is to fix the issue without otherwise altering functionality.

I wouldn't combine a bugfix with a change like that.

@adridev
Copy link

adridev commented Sep 14, 2016

It's true, you are right.

@aik099
Copy link
Member

aik099 commented Sep 14, 2016

How about this? doriancmore@e2710a2

@adorin , the $this->executeScript("document.activeElement && document.activeElement.blur()"); can be replaced with $this->blur($xpath);. As long as tests pass that would solve this problem.

@adridev , I've suggested an update to @adorin solution according to your suggestion.

@kwoxer
Copy link

kwoxer commented Sep 19, 2016

Same for me in Chrome Version 53.0.2785.101.

It helped to delete Key::TAB in line 681

$value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value . Key::TAB;

... as already said above. But untested in current Firefox.

@kwoxer
Copy link

kwoxer commented Sep 19, 2016

Also #194 seems to be identical.

@cocciagialla
Copy link

cocciagialla commented Oct 21, 2016

@lifeofguenter it seems that the TAB doesn't work only for password type inputs.

For example, this worked for me:

// Add the TAB key to ensure we unfocus the field as browsers are triggering the change event only
// after leaving the field.
$value = str_repeat(Key::BACKSPACE . Key::DELETE, $existingValueLength) . $value;
if ($elementType != 'password'){
   $value .= Key::TAB;
}

I think is not a BC break to exclude only password type.

@aik099
Copy link
Member

aik099 commented Oct 22, 2016

@cocciagialla , did #244 work for you as well? A bonus side effect from #244 is ability to test jQueryUI.Autocomplete and similar controls.

@cocciagialla
Copy link

@aik099 yes it works perfectly. I hope it will be merged soon.

@aik099
Copy link
Member

aik099 commented Oct 23, 2016

Just merged #244. Happy test running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants