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

Selenium+Python无法定位已存在元素问题求助

Shopify后台自动化:Selenium定位按钮失败求助

我是一名业余开发者,正在用Python+Selenium自动化Shopify电商后台的重复操作以节省时间。目前已完成部分步骤,但卡在定位某个按钮的环节:浏览器中可通过检查元素复制XPath,但运行代码时无法找到该元素,已查阅大量相关问题仍未解决,恳请帮助。

错误信息

TimeoutException                          Traceback (most recent call last)
Cell In[62], line 221
218     WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[normalize-space()='Páginas']"))).click()
220     # Clique no botão 'Adicionar Páginas'
--> 221     WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="app"]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div/div/a/span'))).click()

TimeoutException: Message:

目标按钮HTML代码

<a href="https://admin.shopify.com/store/dc7020-3/pages/new" data-polaris-unstyled="true" class="Polaris-Button_r99lw Polaris-Button--pressable_1q8ey Polaris-Button--variantPrimary_1stsb Polaris-Button--sizeMedium_5f35p Polaris-Button--textAlignCenter_1kere"><span class="">Adicionar página</span></a>

已尝试的解决方式

  • 等待方法:试过find_element、element_to_be_clickable、presence_of_all_elements_located等
  • 定位方式:试过By.XPATH、By.ID、By.CSS_SELECTOR、By.NAME等
  • 操作时机:即使页面完全加载后再运行点击代码,仍无法找到元素

当前运行的部分代码

# Navigate to the "Pages" tab only the first time
if i == 0:
    # Click on the 'Pages' tab
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[normalize-space()='Páginas']"))).click()

    # Click on the 'Add Pages' button
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="app"]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div/div/a/span'))).click()

内容的提问来源于stack exchange,提问作者Jorge Pedro Souza Silva

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 07:53:34