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

Fixed the way to set value in fields to support events properly #146

Merged
merged 2 commits into from
May 11, 2014

Conversation

}
// Add the TAB key to ensure we unfocus the field as browsers are triggering the change event only
// after leaving the field.
$value .= Key::TAB;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after merging https://github.com/Behat/MinkSelenium2Driver/pull/123 the event count went down from 2 to 0, because the field was not unfocused anymore (looks like applying Syn forced the unfocus) and so the native event was not triggered either.
Well searching on Google about the issue, I found a tip about putting a TAB at the end of the keys being sent, and it indeed works.

@stof
Copy link
Member Author

stof commented May 11, 2014

Yeah, the tests are fixed (the remaining failure is not in the scope of what I was planning to fix for this PR as it is a different issue)

@stof
Copy link
Member Author

stof commented May 11, 2014

and the remaining failure of this PR is fixed by https://github.com/Behat/MinkSelenium2Driver/pull/147

break;
if (in_array($elementName, array('input', 'textarea'))) {
$existingValueLength = strlen($element->attribute('value'));
for ($i = 0; $i < $existingValueLength; $i++) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that here, I avoid reading the value through Selenium for each iteration of the loop. It was the case previously, which is a bad idea considering perf.

From a quick benchmark, str_repeat is 1000 times faster than doing a for
loop concatenating the string.
$element->clear();
break;
if (in_array($elementName, array('input', 'textarea'))) {
$existingValueLength = strlen($element->attribute('value'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to get current value is WebDriver call instead of reading value attribute? Also I bet this won't work for textarea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If might work currently because of a logic of attribute call:

  1. return value of HTML attribute if it exists
  2. if HTML attribute doesn't exist (that's the case with textarea), then take JS property with same name

Maybe we need to be more precise with case of textarea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, according to what I found with Google, $element->attribute('value') seems to be the native way to get the content of a textarea in WebDriver

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However looking at Google Search results on that topic the current solution seems to be the one that worked for all.

stof added a commit that referenced this pull request May 11, 2014
Fixed the way to set value in fields to support events properly
@stof stof merged commit 3597c70 into minkphp:master May 11, 2014
@stof stof deleted the change_event branch May 11, 2014 07:49
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

Successfully merging this pull request may close these issues.

2 participants