问题描述
我的代码是这样的:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
class instagrambot:
def __init__(self,username,password):
self.username = username
self.password = password
self.bot = webdriver.Firefox(executable_path='F:\\PUNEET\\python\\SETUP\\geckodriver-v0.28.0-win64\\geckodriver.exe')
def login(self):
bot = self.bot
bot.get('https://www.instagram.com/accounts/login')
time.sleep(5)
bot.find_elements_by_name('username').send_keys(self.username)
insta = instagrambot('username','password')
insta.login()
我收到此错误:
AttributeError: 'list' object has no attribute 'send_keys'
我能做什么? 我也从名称更改为 xpath 但这不起作用
解决方法
Sendkeys 作用于单个元素。您拥有的是一个元素列表(不确定为什么需要一个列表?)通常登录页面中只有一个用户名字段。使用 FindElement(注意不是 FindElementS)来查找要发送键的元素。