【发布时间】:2021-10-17 23:14:37
【问题描述】:
selenium,如何使用 send_keys() 在 WhatsApp 中向发送者发送表情符号? .我不想通过单击那个表情符号按钮来发送表情符号,但我只想复制在 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)
我尝试使用此代码发送表情符号,但这实际上是有效的,但它在 whatsapp 类型栏中发送了两次,但在终端中仅针对特定表情符号打印一次,例如它在终端“????”中打印此代码并且在whatsapp类型栏中输入相同的代码“?????????” .任何人都可以帮助我为什么它在 WHATSAPP TYPEBAR 中打印两次,但在终端中只打印一次???我也想将该表情符号附加到列表中,但是在附加该表情符号时,在打印列表后,它会给出一个元素为“无”的列表。这是完整的代码
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:\Users\PRANAV PATIL\Downloads\chromedriver.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)
【问题讨论】:
标签: python selenium selenium-webdriver whatsapp emoji