I wanted to verify the meta keywords in our site. To verify, I used toHaveAttribute
and this xpath:
page.locator('[name="keywords"]');
My scenario is:
- Go to view page source
- Locate the meta keywords:
- Verify if the expected and actual string matched by using
toHaveAttribute
But somehow when checking the meta keywords it didn't pass. I am using the same method/script when checking the meta description and it works. Now I am confused why it is not working when checking the meta keywords. Here is my script:
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await page.goto('https://stage-unientwww.euwest01.umbraco.io/');
await page.getByLabel('User name').click();
await page.getByLabel('User name').fill('unienttest');
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill('Unient1234');
await page.getByRole('button', { name: 'Log in' }).click();
await page.getByRole('button', { name: 'Accept All' }).click();
await page.getByRole('heading', { name: 'Your Versatile Partner for Better Offshoring' }).click({
button: 'right'
});
await page.goto('view-source:https://stage-unientwww.euwest01.umbraco.io/');
const Keywords = page.locator('[name="keywords"]');
await expect(Keywords).toHaveAttribute('content','Unient, bpo company, outsource company, bpo company philippines, bpo outsource, one outsource, offshoring australia, outsourcing philippines, outsourced bpo, bpo companies.');
The meta element:
<head>
<meta name="description" content="Empower your business to function onshore and offshore as one enterprise with Unient's versatile range of services and regional service delivery capabilities."
<meta name="keywords" content="Unient, bpo company, outsource company, bpo company philippines, bpo outsource, one outsource, offshoring australia, outsourcing philippines, outsourced bpo, bpo companies"
</head>