无法使用 Selenium 单击 linkedin 上的职位页面上的元素

问题描述 投票:0回答:1

我无法通过 linkedin 上的“轻松申请”选项点击任何职位页面上的“轻松申请”按钮。

使用 selenium 驱动程序导航到任何作业页面后,我使用文本和完整 xpath 尝试了以下操作:

WebDriverWait(driver,15).until(EC.element_to_be_clickable((By.XPATH,"//span[normalize-space()='Easy Apply']"))).click()

WebDriverWait(driver,15).until(EC.element_to_be_clickable((By.XPATH,"//span[normalize-space(.)='Easy Apply']"))).click()

WebDriverWait(driver,15).until(EC.element_to_be_clickable((By.XPATH,"/html/body/div[5]/div[3]/div[2]/div/div/main/div/div[1]/div/div[1]/div/div/div[1]/div[6]/div/div/div/button"))).click()

对于这三个,我得到

selenium.common.exceptions.TimeoutException

我该如何解决这个问题,请帮忙?

python selenium-webdriver selenium-chromedriver
1个回答
0
投票

你的选择器似乎是错误的。 这可以点击您正在寻找的按钮:

button_apply = driver.find_element(By.XPATH, "//div[button/@class='jobs-apply-button artdeco-button artdeco-button--3 artdeco-button--primary ember-view']")

这是我用于此问题的完整代码:

from selenium import webdriver
from selenium.webdriver.common.by import By

# Create a new instance of the Chrome driver
driver = webdriver.Chrome()

# Set implicit wait to wait to poll the DOM for a certain amount of time 
when trying to find any element (or elements) not immediately available.
driver.implicitly_wait(15) 

# Open the website. Manual connection to Linkedin website is required here.
driver.get(r'https://www.linkedin.com/jobs/collections/recommended/?currentJobId=3970401749&eBP=CwEAAAGRIvZBxDHi5DSUXb9ts2v5F0VXmSKobS7tfh6OsBkVfZDP1b20VMNuQGwnHOh2OXY1mR4aa23XMzFkuJ1zEwJ7gJaF1mHkHdI7goN4Uv1E-OmAEyaslvRKHVAjjQmTu9uHFfFK45aw0IucpazTUYzkBHVic6IEgKCInp9wKwpm3vJ6DQy4CpfMS1f6KwUo2E5DGP-7H6aoz7ABmxNHVe3on5k4wlLRo0Q99aBRiXmGAkaP_UcIvPgmvzj6RBSRvjiZ-qbCBqGb4v_qXdjQpwKzZfxITP3N3PfNPe6CvLvgJcQcKPGNJa3vWk9F0zqv4LPfiPk86mTgoQCxoANHloAhnL1geV3kGdSPeo9251V7VulRucRmWPmsY9Iaii8FGAK7udozeVR0xkzVB5YZuiy2y764HhtT1Wb_jse8ey9yQ7mWzHVfSbNFm4ddYe-uZktccw&refId=YHM%2BbmCkMZ5cg8FuYEt%2F6A%3D%3D&trackingId=cKVa8%2FV%2BrV3nLG33mwzD%2FA%3D%3D')

try :
    # Find the button
    button_apply = driver.find_element(By.XPATH, "//div[button/@class='jobs-apply-button artdeco-button artdeco-button--3 artdeco-button--primary ember-view']")

    # Printing text of the button for testing purpose 
    print(button_apply.text) # Easy Apply

    # Click on the button
    button_apply.click()
except Exception as e:
    print(e)

来源:定位-XPATH-Elements隐式等待

© www.soinside.com 2019 - 2024. All rights reserved.