Selify,如何在WhatsApp中用Send_Key()向发送者发送表情包?中用、表情、如何在、Selify

2023-09-03 14:11:44 作者:怕孤却习惯一个人

Selify,如何在WhatsApp中用Send_Key()向发送者发送emoji?我不想通过点击表情按钮来发送表情,但我想复制已经在WhatsApp的短信中发送给我们的表情,并将相同的表情发送给发送者。我在@Cruisepandey的帮助下尝试过

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




    
上面的代码打印聊天的所有表情符号。但如果使用此代码,则会产生

错误
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')) 

此代码给出错误=消息:未知错误:ChromeDriver仅支持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) 

                                                                   
哈利波特 魔法觉醒 首次iOS测试TestFlight下载指引

我尝试了这个代码来发送emoji表情,但它实际上是通过使用这个来工作的,但它在WhatsApp Typebar中发送了两次,但只在终端中打印了一次特定emoji表情,例如它在终端&&qot;中打印了这一点,并且在WhatsApp typebar&&q;中输入了相同的代码类型。谁能告诉我为什么它在WhatsApp TYPEBAR中打印两次,而在终端中只打印一次?我还想将该emoji添加到列表中,但当添加该emoji时,在打印列表后,它会给出一个包含元素=&Quot;None&Quot;的列表。这是完整的代码

 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)

推荐答案

关于两次键入:尝试如下所示,而不是type.send_keys(Keys.CONTROL + "V")。这对我很管用。

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