Home > database >  Compare Two Locator Values in Plawright
Compare Two Locator Values in Plawright

Time:11-26

I was wondering if it was possible to compare two page.locator values.

Ex. Say I have a product number that I store in a variable (ex. const poNumber = page.locator(xpath to element). I want to take this value and compare it with another page.locator value. Would this be possible

CodePudding user response:

You could do it like this with assertions:

const poNumber = await page.locators(`foo`).inputValue();
const val2 = await page.locators(`barbaz`).inputValue();
expect(val2).toEqual(poNumber);

Or:

const poNumber = await page.locators(`foo`).inputValue();expect(await page.locators(`barbaz`).inputValue()).toEqual(poNumber);

Or just take both values and do a string comparision:

if (poNumber === val2) {...}
  • Related