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

Python使用Selenium无法定位目标站点登录邮箱、密码及登录按钮元素求助

前置注意事项

该站点登录表单嵌套在独立子iframe中,直接在根文档上下文定位会失败,需要先切换到对应iframe上下文,Python Selenium示例代码如下:

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

# 等待iframe加载完成后切换
login_iframe = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//iframe[contains(@src,"login")]')))
driver.switch_to.frame(login_iframe)

各元素定位方式

切换iframe后可使用以下方式定位目标元素,均支持XPath、CSS选择器两种写法:

  • 邮箱输入框
    • XPath://input[@name="username" or @type="email"]
    • CSS选择器:input[name="username"], input[type="email"]
  • 密码输入框
    • XPath://input[@type="password"]
    • CSS选择器:input[type="password"]
  • 登录提交按钮
    • XPath://button[@type="submit" or contains(text(),"Zaloguj")]
    • CSS选择器:button[type="submit"]

建议所有元素定位都搭配显式等待逻辑,避免页面未渲染完成导致的定位失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 12:09:02