-
Notifications
You must be signed in to change notification settings - Fork 163
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
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; |
There was a problem hiding this comment.
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.
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) |
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++) { |
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- return value of HTML attribute if it exists
- 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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Fixed the way to set value in fields to support events properly
Closes https://github.com/Behat/MinkSelenium2Driver/issues/143
Refs https://github.com/Behat/MinkSelenium2Driver/issues/136