0

I would like to know if I could call a function or an action, when a variable is utilized.

I have the text variable:

text = "This is My text, and I would like HERE a Smiley, but i'm not satisfied, so I want here a smiley with sunglasses, and right after HERE I would like an emoji with a heart."

Now, due to the fact with selenium I have to use javascript inject in order to put an emoji, and due to the fact it could not be done when the variable is initialized because the input does still not exist, is there a way to call a function which +='s the already inputted text with the unicode text? There are too many strings to be able to write a function for each, and too many sentences with emoji to write them down one by one.

what I would like to accomplish is something like this:

text = "I would like a " + emoji('heart') + " And that was great, but here I would like a " + emoji('sunglasses') + " And a magnificient" + emoji(unicorn)

this is the function which writes letter per letter the string: (where text is keys)

for key in keys:
 print(key)

and in which, reached the emoji() calls the function which inject's a += emoji in the innerHTML.

I already have the emoji's unicode and everything, I'm missing the dynamic string function call that gets called once for example "I would like a" had already been written char by char, function gets called, emoji injected and it continues to write the string.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
  • 1
    Why can't you just put emojis directly in the string? `text = "I would like a ❤"` ? – Blorgbeard Apr 24 '19 at 22:08
  • Your question is not clear. What's wrong with the code in the second snippet? Why doesn't that work? – Daniel Roseman Apr 24 '19 at 22:12
  • Because it's not supported. Using Python and selenium with the chrome driver after 2 hours of research You must inject a script which does a += and the unicode into the innerHtml. – CrazyAsker Apr 24 '19 at 22:13
  • @DanielRoseman Because the function would get called when the variable is declared, not when it's used. it should write the initial string, THEN call the function which injects javascript which replaces (with a +=) the already written text and injects an emoji and then continue with the other text, and when reaching again another function should evaluate the function which will inject another emoji with the previous text before (+=). – CrazyAsker Apr 24 '19 at 22:13
  • Can you add the code where you pass the string to selenium? – Blorgbeard Apr 24 '19 at 22:22
  • Ah, you're talking about [this problem](https://stackoverflow.com/questions/45330640/python-selenium-send-keys-emoji-support)? – Blorgbeard Apr 24 '19 at 22:23
  • @Blorgbeard Yes. Due to the fact I'm not able to pass the emoji directly, I would like to specify a set of phrases where there is catch like a function call, once the characters before the trigger gets written, had it got to the trigger it will call a function which will += the inner html with the past written characters, injecting the emoji. I'm failing to find a way to add a "trigger" directly in the string variable which once processed by the character writer in that moment it queries the function which injects the emoji – CrazyAsker Apr 24 '19 at 22:31
  • I solved the issue, I was maybe just too lazy – CrazyAsker Apr 24 '19 at 22:43
  • @Blorgbeard , Could I ask You if there is a way to write AFTER the entered text when a the javascript had been Injected? I fixed the issue up, but when the function gets executed and the javascript injected with the driver.execute_script, when it gets back to writing character by character it starts from the beginning of the input, not from where it was, like it lost focus and starts writing again in the box (while the previous text is in front where it's writing) – CrazyAsker Apr 24 '19 at 22:47

0 Answers0