babalae/better-genshin-impact · error · InvalidOperationException

未能选择材料筛选类型:{materialType}

Error message

未能选择材料筛选类型:{materialType}

What it means

Thrown as InvalidOperationException by CraftMaterialTask.SelectMaterialType when TrySelectMaterialType returns false, meaning the filter-type selection popup either timed out or the expected materialType text button was not found/clickable. The method first tries a quick confirmation, then opens the filter popup and clicks the category; failure at either step (caught TimeoutException → return false) triggers this.

Source

Thrown at BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs:279

    /// </summary>
    /// <returns>处于合成界面时返回 true。</returns>
    private bool IsInCraftingUi()
    {
        return ContainsText(Rect1080(40, 960, 720, 105), "筛选")
               && ContainsText(Rect1080(0, 0, 260, 95), "合成");
    }

    /// <summary>
    /// 选择材料筛选类型,失败时抛出异常。
    /// </summary>
    /// <param name="materialType">材料筛选类型。</param>
    /// <returns>异步任务。</returns>
    /// <exception cref="InvalidOperationException">未找到或无法点击筛选类型时抛出。</exception>
    private async Task SelectMaterialType(string materialType)
    {
        if (!await TrySelectMaterialType(materialType))
        {
            throw new InvalidOperationException($"未能选择材料筛选类型:{materialType}");
        }
    }

    /// <summary>
    /// 在筛选弹窗中选择指定材料类型。
    /// </summary>
    /// <param name="materialType">材料筛选类型。</param>
    /// <returns>选择成功时返回 true。</returns>
    private async Task<bool> TrySelectMaterialType(string materialType)
    {
        try
        {
            var confirmation = await Page.GetByText(materialType, Rect1080(165, 1000, 279, 34)).TryWaitFor(300);
            if (confirmation.Count > 0)
            {
                return true;
            }
            await Page.GetByText("筛选", Rect1080(90, 1000, 60, 33)).Click(3000);

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Verify the materialType string exactly matches a visible filter category name in the current game version.
  2. Increase the timeout passed to GetByText(...).Click() or add retry logic.
  3. Ensure the game UI language matches the expected Chinese category names.

Example fix

null
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

null

Try / catch

for (int attempt = 0; attempt < 3; attempt++)
{
    try { await task.Start(ct); break; }
    catch (InvalidOperationException ex) when (ex.Message.Contains("材料筛选类型")) { /* wait, retry */ } }

Prevention

When it happens

Trigger: The materialType string passed does not match any visible text button in the filter popup (wrong name, wrong language). The popup did not open due to UI lag. The click landed but the selection confirmation did not appear within the timeout.

Common situations: The materialType value is from an outdated item.csv that doesn't match the current game's filter category names. Game UI language mismatch. Game animation/loading delay caused the popup to not render in time. The crafting UI layout changed in a game update.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/7b21cf7abd71df2c. Report an issue: GitHub.