每当我运行代码时,它会打开instagram页面大约两秒钟,直到它关闭,然后它给我这个错误:'WebDriver'对象没有'find_element_by_name'属性
每当我运行代码时,它会打开instagram页面大约两秒钟,直到它关闭,然后它给我这个错误:'WebDriver'对象没有'find_element_by_name'属性
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time, random
#Username and password of our instagram account
my_username = 'a'
my_password = 'm'
#Instagram username list for DM:
usernames = ['user1', 'user2', 'user3',]
#Messages:
messages = ['Hey! Please follow my page', 'Hey, how are you doing?', 'Hey']
#Delay time between messages in sec:
between_messages = 2000
browser = webdriver.Chrome('chromedriver')
# Authorization:
def auth(username, password):
try:
browser.get('https://instagram.com')
time.sleep(random.randrange(2,4))
input_username = browser.find_element_by_name('username')
input_password = browser.find_element_by_name('username')
input_username.send_keys(username)
time.sleep(random.randrange(1,2))
input_password.send_keys(password)
time.sleep(random.randrange(1,2))
input_password.send_keys(Keys.ENTER)
except Exception as err:
print(err)
browser.quit()
auth(my_username, my_password)
1条答案
按热度按时间nukf8bse1#
find_element_by_name
和其他以find_element_by
开头的方法在Selenium 4.0.0中的this commit中已被弃用,并且从Selenium 4.3版本的this pull request中已被删除。前面提到的PR中有一个注解,说明如何更新代码以使用find_element()
方法,而不是find_element_by_name
、find_element_by_id
等。尝试将您的
find_element_by_name
呼叫更改为以下内容:请记住将以下内容添加到导入中,否则上面两行将不起作用: