Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

python - selenium ,how to send emoji to sender in whatsapp with send_keys()?

selenium ,how to send emoji to sender in WhatsApp with send_keys()? . i dont want to send emoji by clicking on that emoji button ,but i want to like just copy the emoji which has been sent to us in text message of whatsapp and send that same emoji to sender . i have tried this as helped by @cruisepandey

chats = driver.find_elements_by_css_selector("img[data-plain-text][crossorigin='anonymous']")
 for chat in chats:
     print(chat.get_attribute('alt'))




    

this above code prints all the emojis of a chat. But by using this code this gives an error of

chats = driver.find_elements_by_css_selector("img[data-plain-text][crossorigin='anonymous']")
     for chat in chats:
         print(chat.get_attribute('alt'))
         type = driver.find_element_by_xpath('//div[@data-tab="6"]')
         type.send_keys(chat.get_attribute('alt')) 

this code gives an error = Message: unknown error: ChromeDriver only supports characters in the BMP

 chats = driver.find_elements_by_css_selector("img[data-plain-text][crossorigin='anonymous']")
 for chat in chats:
     print(chat.get_attribute('alt'))
     type = driver.find_element_by_xpath('//div[@data-tab="6"]')
     pyperclip.copy(chat.get_attribute('alt'))
     type.send_keys(Keys.CONTROL + "V")
     time.sleep(1) 

                                                                   

i tried this code to send emoji but this by using this actually it works but it sends twice in whatsapp typebar but prints only once in terminal for a particular emoji for eg it prints this in terminal "??" and same code types this in whatsapp typebar "????" . CAN ANYONE HELP ME WHY IT IS PRINTING TWICE IN WHATSAPP TYPEBAR BUT ONLY ONCE IN TERMINAL ??? i also want to append that emoji into a list ,but when appending that emojis ,after printing list ,it gives a list with elements ="None" . This is complete code

 from selenium import webdriver
 from selenium.webdriver.common.keys import Keys
 from selenium.webdriver.common.by import By
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.support import expected_conditions  
 import time
 import pyperclip
 driver = webdriver.Chrome(r'C:UsersPRANAV PATILDownloadschromedriver.exe')
 driver.get(r'https://web.whatsapp.com/')
 searchbox = WebDriverWait(driver, 
     10).until(expected_conditions.presence_of_element_located((By.XPATH, 
     "//div[@id='side']//div//div//label//div//div[@contenteditable='true']")))
 searchbox.send_keys('')  #enter your sender's name
 searchbox.send_keys(Keys.RETURN)
 time.sleep(2)
 chats = driver.find_elements_by_css_selector("img[data-plain-text][crossorigin='anonymous']")
 for chat in chats:
     print(chat.get_attribute('alt'))
     type = driver.find_element_by_xpath('//div[@data-tab="6"]')
     pyperclip.copy(chat.get_attribute('alt'))
     type.send_keys(Keys.CONTROL + "V")
     time.sleep(1)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Regarding that typing twice : Instead of type.send_keys(Keys.CONTROL + "V"), try like below. It worked for me.

type.send_keys(Keys.CONTROL+"v")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...