进入“人物搜索”后,无法在LinkedIn中选择“所有过滤器”-无论尝试如何,Find_element均不起作用

时间:2019-01-15 02:47:03

标签: python selenium

编写简单的python代码以执行以下操作: 1.登录linkedin 2.点击搜索,然后点击人 3.点击“所有过滤器”以进一步修改搜索

我陷入了第3步,无法让驱动程序选择并单击“所有过滤器”

我尝试通过xpath查找find_element,但是它是动态的并且会发生变化 我试图通过文本“所有过滤器”来查找find_element,但仍然无法正常工作

由于某种原因,当我右键单击“所有过滤器”按钮并单击“检查”时,它首先将我带到了而不是实际的按钮;我必须右键单击-第二次查看;这使我认为按钮是隐藏的,我不确定如何继续。

from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.common.action_chains import ActionChains  
import pynput.mouse as ms  
import pynput.keyboard as kb  
import time  

driver = webdriver.Chrome("C:/Users/akame/Documents/PythonFiles/chromedriver.exe")  
act = ActionChains(driver)  


driver.get ('https://www.linkedin.com/')  
driver.maximize_window()  




login_email = driver.find_element_by_id('login-email')  
login_password = driver.find_element_by_id('login-password')  
submit1 = driver.find_element_by_id('login-submit')  
mouse = ms.Controller()  
keyboard = kb.Controller()  

login_email.send_keys(‘XXXXX’)  
login_password.send_keys('XXXXXX')  
submit1.send_keys(u'\ue007')  

searchfield = driver.find_element_by_xpath('//*[@id="ember49"]/input')  
act.click(searchfield).perform()  
act.send_keys(Keys.ARROW_DOWN).perform()  
act.send_keys(Keys.ENTER).perform()  

time.sleep(5)  

#this is where it does not work--->  
button_af = driver.find_element_by_text('All Filters')  
button_af.click()  

1 个答案:

答案 0 :(得分:0)

尝试下面的代码,或仅将button_af = driver.find_element_by_text('All Filters')替换为button_af=find_element_by_xpath("//span[@class='artdeco-button__text' and text()='All Filters']"),因为有时元素文本中有换行符\r\n,您应该始终尝试使用{{ 1}}而不是contains来获取元素的文本:

==