我正在尝试使用python selenium登录我的linkedin。我可以打开我的主页,但之后我想打开主页上的以下链接
<a href="/profile/edit?trk=nav_responsive_sub_nav_edit_profile">
Edit Profile
</a>
我使用了下面的代码来打开我的主页-
import getpass
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
url = "https://www.linkedin.com/uas/login"
driver = webdriver.Firefox()
driver.get(url)
username = 'email-id'
password = 'password'
user = driver.find_element_by_name("session_key")
for j in username:
user.send_keys(j)
pasw = driver.find_element_by_name("session_password")
for j in password:
pasw.send_keys(j)
driver.find_element_by_css_selector("div.form-buttons>input").click()
driver.find_element_by_link_text("Edit Profile").click()
但我得到了以下错误信息-
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"link text","selector":"Edit Profile"}
似乎“编辑配置文件”只是“配置文件”下拉菜单的一个选项,所以它的缩写不可见。你应该先点击“个人资料”打开下拉菜单。尝试:
更新
使用
XPath
:听起来您的问题可能可以通过显式地等待页面上出现的元素来解决。参见以下文档的5.1节显式等待
http://selenium-python.readthedocs.io/waits.html
像这样的:
注意:输入用户名、密码并单击提交后,应使用显式等待
相关问题 更多 >
编程相关推荐