如何使用selenium python注销linkedin

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用selenium python注销linkedin相关的知识,希望对你有一定的参考价值。

我试图使用以下代码从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:UsersShivamDocumentsscrapinchromedriver.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()
答案

您不能依赖这些余烬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()

以上是关于如何使用selenium python注销linkedin的主要内容,如果未能解决你的问题,请参考以下文章

如何从不同的活动中注销G + plus sigin?

如何在 selenium webdriver 中自动化桌面通知 - ruby

如何从 Selenium 处理 Shadow DOM 中的元素

Python+Selenium练习篇之4-利用link text定位元素

Python+Selenium练习篇之5-利用partial link text定位元素

Selenium3自动化测试17元素定位之Link定位