如何使用selenium python注销linkedin

问题描述 投票:0回答:1

我试图使用以下代码从linkedin注销,但它给了我这个错误:AttributeError:'list'对象没有属性'click'

登录成功但它没有注销注销代码并退出。

  

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from bs4 import BeautifulSoup
import time


driver = webdriver.Chrome(executable_path=r'C:\Users\Shivam\Documents\scrapin\chromedriver.exe')
driver.get('https://www.linkedin.com/uas/login?goback=&trk=hb_signin')

driver.maximize_window()

email = driver.find_element_by_xpath('//*[@id="username"]')


email.send_keys('******')

time.sleep(3)

password = driver.find_element_by_xpath('//*[@id="password"]')
password.send_keys('*******')


time.sleep(3)

login = driver.find_element_by_xpath('//*[@id="app__container"]/main/div/form/div[3]/button')
login.click()

time.sleep(3)

logout = driver.find_elements_by_xpath('//*[@id="ember1016"]')
logout.click()
python selenium
1个回答
-1
投票

您不能依赖这些余烬ID,因为它们是在页面加载时动态生成的。例如,当我加载页面时,“注销”按钮具有id="ember1203"。另外,在点击之前,您需要单击按钮打开Sign Out所在的下拉列表。请尝试以下操作,而不是当前的注销代码:

dropdownButton = driver.find_element_by_css_selector('#nav-settings__dropdown-trigger')
dropdownButton.click()
signoutButton = driver.find_element_by_xpath('//*[@href="/m/logout/"]')
signoutButton.click()
© www.soinside.com 2019 - 2024. All rights reserved.