硒不能单击按钮

时间:2020-02-08 19:07:50

标签: python-3.x selenium selenium-webdriver

如何单击此页面上的“查看个人资料”按钮。

问题::当我要复制“查看个人资料”按钮的XPath时,该按钮消失。

https://www.linkedin.com/sales/search/people?savedSearchId=515913166

[enter image description here]

另一张图片 enter image description here

这是我的代码。从config.txt文件读取电子邮件和密码。 转到linkedin站点,然后转到Sales Navigator 我的代码

import os, random, sys, time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup

browser = webdriver.Chrome('driver/chromedriver')

browser.get('https://www.linkedin.com/uas/login')

file = open('config.txt')
lines = file.readlines()
username = lines[0]
password = lines[1]

elementID = browser.find_element_by_id('username')
elementID.send_keys(username)

elementID = browser.find_element_by_id('password')
elementID.send_keys(password)

visitingSalesNavID = '/sales/homepage/'
fullLink = 'https://www.linkedin.com' + visitingSalesNavID
browser.get(fullLink)

time.sleep(4)

SavedSearchesID = '/sales/search/saved-searches/people'
fullLink = 'https://www.linkedin.com' + SavedSearchesID
browser.get(fullLink)

time.sleep(4)

SavedSearchID = '/sales/search/people?savedSearchId=515913166'
fullLink = 'https://www.linkedin.com' + SavedSearchID
browser.get(fullLink)

time.sleep(4)

browser.find_element_by_xpath('/html[1]/body[1]/div[5]/main[1]/div[1]/div[1]/section[1]/div[1]/ol[1]/li[1]/div[2]/div[1]/div[1]/div[1]/article[1]/section[1]/div[2]/ul[1]/li[1]/div[1]/div[2]/div[1]/div[1]/button[1]/li-icon[1]/*').click()

2 个答案:

答案 0 :(得分:1)

您必须冻结DOM:

1)打开开发控制台(F12键)

2)选择sources标签

3)单击F8冻结DOM

然后随便做什么

答案 1 :(得分:0)

您无需查看元素的详细信息。您可以单击text。打开菜单后,尝试以下代码。

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 50).until(
    EC.presence_of_element_located((By.XPATH, "//*[contains(., 'View profile')]")))
element.click()