Reputation: 351
I want to validate if the text in my page is left or right aligned.
In selenium one can use driver.findElement(By.id("id1")).getLocation().x;
to get the location of an element in the page based on which the alignment can be deduced.
What is the equivalent approach in Playwright?
Upvotes: 1
Views: 617
Reputation: 4199
Instead of relying on precise co-ordinates which is an fragile approach in my opinion , you may use getAttribute property to fetch the style(or some other property as applicable in your scenario) detail which confirms the alignment property per your use case.
let locator = page.locator("someText")
let styleValue = await locator.getAttribute('style')
expect(styleValue).toContain('left');
Upvotes: 2
Reputation: 992
It looks like bounding box is similar to what you had in Selenium:
const box = await page.locator('#id1').boundingBox();
expect(box.x).toBeLessThan(100);
Upvotes: 1