0

I have to colour an element after the selection, the element which i would like to colour is found as a child of the following sibling.

I have successfully located the element using the following code

page.getByRole(AriaRole.COMBOBOX, new Page.GetByRoleOptions().setName("* Legal Type"))

How can I go to the following sibling from this element and then locate the child of that following-sibling?

Any help?

hardkoded
  • 18,915
  • 3
  • 52
  • 64
Rajagopalan
  • 5,465
  • 2
  • 11
  • 29

1 Answers1

0

Maybe there are better ways to solve this. But I think you will need to use an XPath locator.

Locator combo = page.getByRole(AriaRole.COMBOBOX, new Page.GetByRoleOptions().setName("* Legal Type"));
Locator child = combo.locator("xpath=./following-sibling::*/*");
  • ./following-sibling::* Will give you the sibling. no matter the tag name (*).
  • /* will give you the child, no matter the tag name.
hardkoded
  • 18,915
  • 3
  • 52
  • 64
  • Hi, Thanks for writing up, I am getting this error `com.microsoft.playwright.PlaywrightException: Error { message='Unexpected token "/" while parsing selector "./following-sibling::*/*"` – Rajagopalan Mar 21 '23 at 03:23
  • Could you try with the new change? – hardkoded Mar 21 '23 at 12:09
  • I tried, but now it's not locating the element. This code works `Locator child = combo.locator("xpath=//label[text()='Legal Type']/following-sibling::div/a");` But when I try to locate by this way, it's selecting the option but it's not colouring and failing. `Locator combo = page.getByRole(AriaRole.COMBOBOX, new Page.GetByRoleOptions().setName("* Legal Type")); Locator child = combo.locator("xpath=.//following-sibling::div/a"); child.evaluate("el => el.style.backgroundColor = 'yellow'");` – Rajagopalan Mar 26 '23 at 09:58