【问题标题】:Clicking Apply LinkedIn button using selenium使用 selenium 单击应用 LinkedIn 按钮
【发布时间】:2020-10-18 20:46:55
【问题描述】:

我正在尝试单击linkedIn 上的“应用”按钮,但是这样做很困难。我尝试以 id 为目标,但我注意到页面重新加载时 id 总是会发生变化。

我试过了:

browser.find_element_by_xpath("//span[text() = 'Apply']").click()browser.find_element_by_xpath("//button[@type = 'Apply']").click() 但它不起作用。

【问题讨论】:

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


    【解决方案1】:

    使用任一xpath

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

    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
    

    【讨论】:

    • 我收到以下消息:元素不可交互
    • @UmmaromanaSama :似乎是同步问题。请检查更新的答案?
    猜你喜欢
    • 2023-04-02
    • 1970-01-01
    • 2020-09-04
    • 2021-01-31
    • 2020-08-06
    • 2017-04-22
    • 1970-01-01
    • 2019-05-30
    • 2018-08-22
    相关资源
    最近更新 更多