【发布时间】:2020-08-16 06:53:26
【问题描述】:
大家好,我真的是 python 的新手,我只是编写了一段代码来打开 Whatsapp
然后你给它这个人的名字,然后你想要的消息发送多少次。
但是当我开始调试代码时,它给了我这个:
Exception has occurred: TypeError 'WebElement' object is not subscriptable File "E:\Iliya\My Courses\Python\Projects\Whatsapp Robot\Whatsapp_Bot.py", line 15, in <module> msg = driver.find_element_by_class_name('_3FRCZ')[1]
# ======================================
from selenium import webdriver
PATH = 'C:\\Program Files (x86)\\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get('https://web.whatsapp.com/')
input("Please Press The 'Enter' Button... ")
name = input("Enter Person's Name: ")
msg = input("Enter The Message: ")
counter = int(input("How Many Times Do You Want To Repeat The Message?: "))
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()
msg = driver.find_element_by_class_name('_3FRCZ')[1]
for i in range(counter):
msg.send_keys(msg)
button = driver.find_element_by_class_name('_1U1xa')[0]
button.click()
请各位擅长python的人回答我!!!????????
【问题讨论】:
-
你为什么不看看
driver.find_element_by_class_name('_3FRCZ')有什么类型?然后你就会知道为什么你不能索引它。只需print(type(driver.find_element_by_class_name('_3FRCZ'))),您就会知道它是什么。
标签: python selenium selenium-webdriver webdriver