Revisiting Multi byte emojis. I started to dig into this some more after I saw that Tim had posted the bug on the selenium GitHub. It seems the issue lies in the sendKeys function in the web driver class. Heres the Traceback i'm sure you're all familiar with.
Traceback (most recent call last):
File "pythonTests.py", line 31, in <module>
inputLine.send_keys(u'\U0001F4AF')
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 349, in send_keys
'value': keys_to_typing(value)})
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 493, in _execute
return self._parent.execute(command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 165, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: missing command parameters
After digging into this I realized it might have something to do with python unicode to browser encoding.
However I was able to send higher byte emojis using the native Javascript "setAttribute" function.
inputLine = driver.find_element_by_id("lst-ib")
driver.execute_script("arguments[0].setAttribute('value','test message with some emojis 馃挴馃挴馃挴')",inputLine);
So my question is 2 fold.
1) Is it worth it to you guys to have more options for emojis?
2) Thinking of detection avoidance: Is there any reason setAttribute might be considered less safe than sendKeys or is it a wash? If so, i'll keep searching for a solution
Note: I tested this code on a google search input window. Just be aware that the element name in find_element_by_id is not the right one for the instagram comment window.
What do you guys think?
@atomhax Awesome, thank you!
This was on the list for InstaPy_V1, the best part with your solution is that you can easily send the actual emojis instead of the unicodes.
I can get started on the pull request for this once @vlntdds can confirm.
@atomhax Feel free to start. @vlntdds has been inactive for quite a while now.
@timgrossmann I created the PR. Setting the value via JS was actually more difficult that I planned. The ultimate interim solution is slightly hackish and i'm sure i'll find another way to force an update. Since Instagram is reactJS, the input box value doesn't automatically update on the reactCore when set via javascript. I had to append an extra " " onto a comment so I can send a backspace "\b" key. This triggers the onChange events and updates the reactCore.
This is based on my limited understanding of ReactJS so if anyone cares to correct me on any errors... please do.
At least it's working. 馃挴
@atomhax Awesome for now!
Next will be to add the emoji lib in case users want the emoji alias support.. like the ":thumbs_up:" that @raffg brought up in #143
But i'll wait until this PR gets accepted.
@atomhax You Sir, are awesome!
I'll keep this one open for the :thumbs_up: PR 馃槈