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

使用Selenium点击Temple Wallet密码输入框失败:无法定位元素选择器的技术求助

Fixing Temple Wallet Password Input Locator Issue in Selenium

Hey there, let's work through why you're struggling to locate that Temple Wallet password input box after clicking the buy button. Here are the most common fixes and actionable steps to get this working:

1. Check if the Input Lives Inside an Iframe

Temple Wallet's authentication popup is almost always loaded inside an <iframe>—Selenium can't find elements inside iframes unless you explicitly switch to that frame first.

How to verify & fix:

  • When the password popup appears, hit F12 to open your browser's DevTools
  • Right-click the password input and select "Inspect"
  • Look up the DOM tree to see if the input is wrapped inside an <iframe> element
  • If yes, switch to that frame before trying to locate the input

Updated code example:

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

driver = webdriver.Chrome()  # Or your preferred browser driver
driver.get("https://objkt.com/asset/hicetnunc/317305")

# Wait for and click the buy button (added wait for reliability)
buy_button = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, "//button[@class='action-button buy mb-20']"))
)
buy_button.click()

# Wait for the Temple Wallet iframe to load, then switch to it
# Replace the iframe selector with the actual one you find in DevTools
temple_iframe = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "//iframe[contains(@src, 'temple-wallet')]"))
)
driver.switch_to.frame(temple_iframe)

# Now locate the password input (use the selector you copied from DevTools)
password_input = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "//input[@type='password']"))
)
password_input.send_keys("your_wallet_password")

# Switch back to the main page when you're done with the iframe
driver.switch_to.default_content()

2. Always Use Explicit Waits

The popup might take a split second to render after clicking "Buy"—trying to locate the input immediately will fail because the element doesn't exist yet. Ditch immediate find_element calls and use WebDriverWait to wait for elements to be present or clickable.

3. Handle Shadow DOM (If Needed)

Some modern web components use Shadow DOM, which hides elements from regular Selenium queries. If DevTools shows the input is inside a shadow root, use JavaScript to access it directly:

Example for Shadow DOM:

# After switching to the iframe (if applicable)
password_input = driver.execute_script("""
    // Replace with the actual shadow host and input selectors from DevTools
    const shadowHost = document.querySelector('temple-password-modal');
    return shadowHost.shadowRoot.querySelector('input[type="password"]');
""")
password_input.send_keys("your_wallet_password")

Pro Tip to Grab the Correct Selector:

When the password popup is visible:

  1. Press F12 to open DevTools
  2. Click the "Select element" tool (cursor icon in the top-left of DevTools)
  3. Click the password input box—DevTools will highlight the element
  4. Right-click the highlighted element in the DOM tree > Copy > Copy XPath (or Copy CSS Selector)
  5. Paste that exact selector into your Selenium code

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 13:17:43