Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带Python Selenium的WhatsApp多行消息_Python_Selenium_Whatsapp_Multiline - Fatal编程技术网

带Python Selenium的WhatsApp多行消息

带Python Selenium的WhatsApp多行消息,python,selenium,whatsapp,multiline,Python,Selenium,Whatsapp,Multiline,我已经找到了一个解决方案(例如在这个链接上) 但我在使用Python和Selenium使用WhatsApp发送多行消息时遇到问题 这是我的代码: message = excel_data['Message'][msg] # Locate search box through x_path search_box = '//*[@id="side"]/div[1]/div/label/div/div[2]' person_title = wait.until(lambda dri

我已经找到了一个解决方案(例如在这个链接上)

但我在使用Python和Selenium使用WhatsApp发送多行消息时遇到问题

这是我的代码:

message = excel_data['Message'][msg]
# Locate search box through x_path
search_box = '//*[@id="side"]/div[1]/div/label/div/div[2]'
person_title = wait.until(lambda driver:driver.find_element_by_xpath(search_box))

# Clear search box if any contact number is written in it
person_title.clear()

# Send contact number in search box
person_title.send_keys(str(excel_data['Contact'][count]))
count = count + 1
msg=msg+1

# Wait for 2 seconds to search contact number
time.sleep(2)

try:
    # Load error message in case unavailability of contact number
    element = driver.find_element_by_xpath('//*[@id="pane-side"]/div[1]/div/span')
except NoSuchElementException:
    # Format the message from excel sheet
    message = message.replace('{customer_name}', column)
    person_title.send_keys(Keys.ENTER)
    actions = ActionChains(driver)
    actions.send_keys(message)
    actions.send_keys(Keys.ENTER)
    actions.perform()
我有一个excel文件,有两列:1列电话号码和2列信息

如果消息是一条单独的消息,那么所有这些都可以正常工作。 如果消息处于多行状态,则无法运行

例:

WhataApp发送3条消息:

First with Hello
Second with Gundam How are you?
Third with I'well
我需要多行的一条信息

你能帮我修改代码吗

我尝试添加此项,但不起作用:

ActionChains(driver).send_keys(message).perform()
        ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
    ActionChains(driver).send_keys(Keys.RETURN).perform()
非常感谢您的帮助

使用selenium键:

from selenium.webdriver.common.keys import Keys
然后:

只需将“\n”或“\r\n”替换为(Keys.SHIFT+Keys.ENTER)

因此,在你的情况下:

首先检查行尾字符是什么

 print((message).encode("unicode_escape"))
然后用键替换。按住shift键并输入

 message=message.replace("\n",(Keys.SHIFT+Keys.ENTER))
您可以直接使用unicode字符:

 elem.send_keys("first\ue008\ue007second")
“它不工作”不是一个可接受的问题陈述。它是如何工作的?当你尝试使用它时发生了什么(不正确的缩进)代码段?有错误吗?如果有,请将全文作为问题本身的文本发布。请将您的问题和完整的文本放在一起,我们可以运行它,并获得与您相同的行为。您发布的代码不可运行,因为它包含多个错误和未定义的变量。帮助我们帮助您。
 message=message.replace("\n",(Keys.SHIFT+Keys.ENTER))
 elem.send_keys("first\ue008\ue007second")