Skip to content

locator.count() returns 0 for valid XPath selector while isVisible() works correctly #1668

Closed

Description

@XSUV
import "dotenv/config";
import { Stagehand } from "@browserbasehq/stagehand";

async function main() {
  const stagehand = new Stagehand({
    env: "LOCAL",
    disableAPI: true,
    verbose: 0 
  });
  await stagehand.init(); 
  const page = stagehand.context.pages()[0];

  // 主执行函数
  async function test() {
    await page.goto("https://www.stagehand.dev/");
    const selector = page.locator("//img[@alt='Stagehand']")
    const count = await selector.count();
    const visible = await selector.isVisible()
    console.log("🚀 ~ test ~ count:", count,visible)
  }
  await test()
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
Image

package.json

{
  "name": "my-stagehand-app",
  "type": "module",
  "scripts": {
    "build": "tsc",
    "start": "tsx index.ts"
  },
  "dependencies": {
    "@ai-sdk/openai-compatible": "^1.0.30",
    "@browserbasehq/stagehand": "^3.1.0-alpha-a7d29decee0f7d12e2437267b9eef1795d3b4e3a",
    "dotenv": "^16.4.7",
    "openai": "^6.17.0",
    "zod": "^4.3.6"
  },
  "devDependencies": {
    "tsx": "^4.19.2",
    "typescript": "^5.0.0"
  }
}

Activity

  1. XSUV commented on Feb 8, 2026

    @XSUV
    Author
    Image
    $x("//img[@alt='Stagehand']") 
  2. added 2 commits that reference this issue on Feb 11, 2026
    c7b68d0
    5764ede
  3. added a commit that references this issue on Aug 4, 2026
    2031aad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions