Send whatsapp message to contacts using Python but getting an error: InvalidSelectorException: Message: invalid selector: Unable to locate an element(使用 Python 向联系人发送 whatsapp 消息但收到错误:InvalidSelectorException: Message: invalid selector: Unable to locate a
问题描述
我正在尝试使用 Python 向联系人发送 whatsapp 消息,但出现错误:InvalidSelectorException:消息:无效选择器:无法使用 xpath 表达式定位元素//span[@title = "Me Postpaid"]"}(会话信息:chrome=73.0.3683.103)(驱动信息:chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 6.1.7601 SP1 x86_64)
I am trying to send whatsapp message to contacts using Python but getting an error:
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,代码如下:
I have used selenium for this and the code is mentioned below:
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()
我怎样才能做到这一点???
How can I make this work ???
推荐答案
click()
不返回任何内容.因此,您需要删除分配并正确替换代码行的格式:
click()
doesn't returns anything. So you need to remove the assignment and format the line of code properly replacing:
user = driver.find_element_by_xpath('//span[@title = " {}"]'.format(name)).click()
与:
driver.find_element_by_xpath('//span[@title= "{}"]'.format(name)).click()
这篇关于使用 Python 向联系人发送 whatsapp 消息但收到错误:InvalidSelectorException: Message: invalid selector: Unable to locate an element的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Python 向联系人发送 whatsapp 消息但收到错误:InvalidSelectorException: Message: invalid selector: Unable to locate an element


基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01