我尝试使用Python向联系人发送whatsapp消息,但收到错误:InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //span[@title = "Me Postpaid"]"} (Session info: chrome=73.0.3683.103) (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 6.1.7601 SP1 x86_64)
我已经使用 selenium 为这和代码如下所述:
from selenium import webdriver
driver = webdriver.Chrome('C:/Users/....../chromedriver_win32/chromedriver.exe')
driver.get('https://web.whatsapp.com/')
name = input('Enter the name of person or group you want to message: ')
msg = input('Enter your Message: ')
count = int(input('Enter how many times you want to send this message: '))
input('Enter any key after scanning QR code')
user = driver.find_element_by_xpath('//span[@title = " {}"]'.format(name)).click()
#user.click()
msg_box = driver.find_element_by_class_name('_1Plpp')
for i in range(count):
msg_box.send_keys(msg)
button = driver.find_element_by_class_name('_35EW6')
button.click()
我该怎么做呢?
2条答案
按热度按时间6ie5vjzr1#
click()
不返回任何值,因此需要删除赋值语句并正确格式化代码行,替换:与:
ctzwtxfj2#
可能是使用speak函数发送whatsapp消息或使用python自动发送whatsapp消息而不使用selenium的简单方法
首先
安装此pip模块后导入它们
发送whatsapp消息的主要语法是
其次,定义一个函数,如下所示:
现在我们已经成功地创建了函数。让我们调用函数