0

Since our elements we need to find (Selenium, Java, Eclipse) are under shadow roots, we have to use CSS selectors in our findElements. Such as

 sc.findElement(By.cssSelector(path))

Now we have several of these tags called like macroponent such as "<macroponent-f51912f4c700201072b211d4d8c26010>" and "<macroponent-76a83a645b122010b913030a1d81c780>". I am assuming these huge numbers after macroponent are some sort of unique id regenerated each time so I can't use them. These are nested under various shadow roots.

I wanted to find by partial tag name, so I read a google site and tried the following:

 tele = sc.findElement(By.cssSelector(path)); // sc is a search context from shadow root

I tried the following four for the path, but they all gave error:

[data-element*='macroponent'] {...}
[data-element*='macroponent']
[data-element*=' macroponent'] {...}
[data-element*=' macroponent']

I really need the space before the "macroponent" to indicate it could be nested. I was able to find the top-level one by using the following. It was also //html//body/macroponent..., directoy under the body. This worked because a) I had an element and not a SearchContext, and b) it was at the top level (under /html/body).

Any suggestion how to get the macroponent tag name with CSS selector (in Java)?

Tony
  • 1,127
  • 1
  • 18
  • 29

0 Answers0