简体   繁体   English

python 使用 selenium 在信使中发送消息

[英]python send message in messenger using selenium

I tried using the following code, I have to manually open the messenger window, It did send the message but after it send one time, it will return me the following error, 'value': keys_to_typing(value)}) return self._parent.execute(command, params)我尝试使用以下代码,我必须手动打开信使 window,它确实发送了消息,但发送一次后,它会返回以下错误,'value':keys_to_typing(value)}) return self._parent .execute(命令,参数)


from selenium import webdriver
driver = webdriver.Chrome("C:\Image\chromedriver.exe")
driver.get('https://www.facebook.com')

for i in range(99):
    name = input('Enter the name of user or group : ')
    msg = input('Enter your message : ')
    count = int(input('Enter the count : '))
    input('Enter anything after scanning QR code')
  #  user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
  #  user.click()

    msg_box = driver.find_element_by_class_name("_1mf._1mj")

    for i in range(count):
        msg_box.send_keys(msg," 第",i,"次")
        button = driver.find_element_by_class_name('_30yy._38lh._7kpi')
        button.click()

Only input element can sendKeys.只有输入元素可以发送密钥。

But the element you try to sendKeys is div .但是您尝试 sendKeys 的元素是div 在此处输入图像描述

I think that the messenger cannot automatically send message with Selenium.我认为信使无法使用 Selenium 自动发送消息。

You can try to use Messenger API to do this.您可以尝试使用 Messenger API 来执行此操作。

The real matter is that you have to take another element to send keys the xpath of the element is //div[@aria-label="Aa"] so the line to find it will be真正的问题是您必须使用另一个元素来发送键元素的 xpath 是//div[@aria-label="Aa"]所以找到它的行将是

driver.find_element_by_xpath('//div[@aria-label="Aa"]')

Liked to help you.喜欢帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM