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

解决Selenium的ElementClickInterceptedException报错(Upwork高级搜索)

解决Upwork高级搜索弹窗Skills Search输入框点击被拦截的问题

针对你遇到的ElementClickInterceptedException(被.up-modal-header拦截)问题,以下是几个适配新版Selenium的可行方案:

方案1:等待元素可交互后点击(优先尝试)

先确保弹窗及输入框完全加载,等待元素处于可点击状态,若直接点击失败则用JavaScript强制触发点击:

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

# 替换为Skills Search输入框的实际选择器(CSS/XPath均可)
skills_locator = (By.CSS_SELECTOR, "input[placeholder='Add skills']")

# 等待元素可点击
skills_input = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable(skills_locator)
)

# 尝试常规点击,失败则用JS点击
try:
    skills_input.click()
except ElementClickInterceptedException:
    driver.execute_script("arguments[0].click();", skills_input)

方案2:直接通过JS输入内容(跳过点击步骤)

如果你的目标是输入技能关键词,无需先点击输入框,直接用JavaScript设置输入值并触发必要事件:

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

skills_locator = (By.CSS_SELECTOR, "input[placeholder='Add skills']")
skills_input = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located(skills_locator)
)

# 设置输入值
driver.execute_script("arguments[0].value = 'Python, JavaScript';", skills_input)
# 触发change事件,确保Upwork识别输入内容
driver.execute_script("arguments[0].dispatchEvent(new Event('change'));", skills_input)

方案3:滚动元素避开遮挡

若.up-modal-header固定在弹窗顶部遮挡输入框,可通过滚动让输入框处于视野中心:

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

skills_locator = (By.CSS_SELECTOR, "input[placeholder='Add skills']")
skills_input = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located(skills_locator)
)

# 滚动到元素中心位置,避开header遮挡
driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", skills_input)

# 等待元素可点击后点击
WebDriverWait(driver, 5).until(
    EC.element_to_be_clickable(skills_locator)
).click()

注意:请根据Upwork页面实际结构替换代码中的元素选择器,可通过浏览器开发者工具获取准确的CSS或XPath表达式。

内容的提问来源于stack exchange,提问作者Info Rewind

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 18:55:12