You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Selenium操作LinkedIn搜索栏遇ElementNotInteractableException问题求助

解决LinkedIn职位搜索栏ElementNotInteractableException错误

问题根源

  1. 选择器匹配错误:你混淆了关键词和位置输入框的aria-label属性,关键词输入框的标签是Search by title, skill, or company,但代码里误用了位置输入框的标签。
  2. 等待条件不足:presence_of_element_located仅确认元素存在于DOM中,不保证元素可见或可交互,此时操作元素必然触发异常。
  3. 位置输入框选择器不准确:.jobs-search-box__input--location是外层容器,真正接收输入的是内部的input元素,直接操作容器无法完成交互。

修复后的代码

def job_search(self):
    """This function goes to the 'Jobs' section and looks for all the jobs that match the keywords and location"""

    # 跳转到LinkedIn职位搜索页面
    self.driver.get("https://www.linkedin.com/jobs")

    # 等待关键词输入框可点击
    search_keywords = WebDriverWait(self.driver, 15).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, ".jobs-search-box__text-input[aria-label='Search by title, skill, or company']"))
    )
    search_keywords.clear()
    search_keywords.send_keys(self.keywords)

    # 等待位置输入框可点击
    search_location = WebDriverWait(self.driver, 15).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, ".jobs-search-box__text-input[aria-label='City, state, or zip code']"))
    )
    search_location.clear()
    search_location.send_keys(self.location)
    search_location.send_keys(Keys.RETURN)

额外提示

  • 确保已登录LinkedIn,未登录状态下搜索栏DOM结构可能变化,还可能弹出登录弹窗干扰操作。
  • 若仍有问题,可添加滚动代码确保元素在视口内:
    self.driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", search_keywords)
    
  • LinkedIn有反爬机制,操作间隔适当延长,避免频繁请求被限制。

内容的提问来源于stack exchange,提问作者With Me

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 05:22:42