如何使用selenium python注销linkedin

如何使用selenium python注销linkedin,python,selenium,Python,Selenium,我正试图使用以下代码从linkedin注销,但它给了我这个错误:AttributeError:'list'对象没有属性'click' 登录成功,但对注销代码和退出不做任何操作 从selenium导入webdriver 从selenium.webdriver.common.keys导入密钥 从selenium.webdriver.common.action\u链导入ActionChains 从bs4导入BeautifulSoup 导入时间 driver=webdriver.Chrome(可执行

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

登录成功,但对注销代码和退出不做任何操作


从selenium导入webdriver
从selenium.webdriver.common.keys导入密钥
从selenium.webdriver.common.action\u链导入ActionChains
从bs4导入BeautifulSoup
导入时间
driver=webdriver.Chrome(可执行文件\u path=r'C:\Users\Shivam\Documents\scrapin\chromedriver.exe')
司机,上车https://www.linkedin.com/uas/login?goback=&trk=hb_signin')
驱动程序。最大化_窗口()
email=driver。通过xpath('/*[@id=“username”]”查找元素
电子邮件。发送密钥(“*******”)
时间。睡眠(3)
password=driver。通过xpath('/*[@id=“password”]'查找\u元素\u
密码。发送密钥(“*******”)
时间。睡眠(3)
login=driver。通过xpath查找元素('/*[@id=“app\uu container”]/main/div/form/div[3]/button'))
登录。单击()
时间。睡眠(3)
logout=driver。通过\u xpath('/*[@id=“ember1016”]'查找\u元素

注销。单击()。例如,当我加载页面时,注销按钮具有
id=“ember1203”
。另外,您需要单击按钮打开“注销”所在的下拉列表,然后才能单击它。请尝试以下操作,而不是您当前的注销代码:

dropdownButton = driver.find_element_by_css_selector('#nav-settings__dropdown-trigger')
dropdownButton.click()
signoutButton = driver.find_element_by_xpath('//*[@href="/m/logout/"]')
signoutButton.click()

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

dropdownButton = driver.find_element_by_css_selector('#nav-settings__dropdown-trigger')
dropdownButton.click()
signoutButton = driver.find_element_by_xpath('//*[@href="/m/logout/"]')
signoutButton.click()

在最后一行,您正在检索元素列表
logout=driver。通过xpath('/*[@id=“ember1016”]')查找元素。
。从要检索元素列表的最后一行的
find_元素
中删除“s”
logout=driver。通过xpath('/*[@id=“ember1016”]')查找元素。
。从
find_元素中删除“s”
谢谢,它成功了。我想再问一件事。如何单击代码中没有ahref链接的按钮,例如linkedin上的主页按钮或我的网络按钮。提前谢谢!谢谢,成功了。我想再问一件事。如何单击代码中没有ahref链接的按钮,例如linkedin上的主页按钮或我的网络按钮。提前谢谢!