单击使用硒的“应用领英”按钮

时间:2020-10-18 20:46:55

标签: python selenium selenium-webdriver xpath selenium-chromedriver

我正在尝试单击linkedIn上的“应用”按钮,但是这样做很困难。我尝试定位ID,但发现页面重新加载时ID总是会更改。

我尝试过:

browser.find_element_by_xpath("//span[text() = 'Apply']").click()browser.find_element_by_xpath("//button[@type = 'Apply']").click(),但无效。

enter image description here

1 个答案:

答案 0 :(得分:0)

使用xpath中的任何一个。

browser.find_element_by_xpath("//span[normalize-space(.)='Apply']").click()

OR

browser.find_element_by_xpath("//span[contains(.,'Apply')]").click()

更新: 似乎同步问题导致WebDriverWait()并等待element_to_be_clickable()

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

您需要导入以下库。

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