Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Locator for 'role=img' sees SVGs with 'role=presentation' as images #26809

Closed
Mamaduka opened this issue Aug 31, 2023 · 1 comment · Fixed by #30408
Closed

[BUG] Locator for 'role=img' sees SVGs with 'role=presentation' as images #26809

Mamaduka opened this issue Aug 31, 2023 · 1 comment · Fixed by #30408

Comments

@Mamaduka
Copy link

System info

  • Playwright Version: 1.37.1
  • Operating System: macOS 13.3
  • Browser: Chromium (but probably affects others)
  • Other info:

Locator

Source code

Test file (self-contained)

const { chromium, test, expect } = require( '@playwright/test' );

test( 'image locator', async () => {
	const browser = await chromium.launch();
	const context = await browser.newContext();
	const page = await context.newPage();

	await page.setContent( `
	<div data-testid="images">
		<img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." />
		<svg class="components-spinner aecf-ce-a-fe-acea-1yxc2ud ea4tfvq2" viewBox="0 0 100 100" width="16" height="16" xmlns="http://www.w3.org/2000/svg" role="presentation" focusable="false"><circle cx="50" cy="50" r="50" vector-effect="non-scaling-stroke" class="aecf-ce-a-fe-acea-5zbsse ea4tfvq1"></circle><path d="m 50 0 a 50 50 0 0 1 50 50" vector-effect="non-scaling-stroke" class="aecf-ce-a-fe-acea-1r60s1s ea4tfvq0"></path></svg>
	</div>
` );

	const image = page.getByTestId( 'images' ).getByRole( 'img' );

	await expect( image ).toHaveAttribute( 'alt', 'Code is Poetry.' );
} );

Steps

  • Run the test
  • Test fails with Error: strict mode violation: getByTestId('images').getByRole('img') resolved to 2 elements

Expected

The test should only locate elements with role images.

Actual

The test incorrectly includes SVG in the located elements list.

This was working in Playwright v1.32.x.

@amankagithub
Copy link
Contributor

amankagithub commented Apr 11, 2024

I am facing the same issue , did we deploy any fix for this ?
PW version 1.41.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants