The page I am testing has the following code:
<code><span class="highlighted">...</span>
...
<span class="selected highlighted">...</span>
</code>
<code><span class="highlighted">...</span>
...
<span class="selected highlighted">...</span>
</code>
<span class="highlighted">...</span>
...
<span class="selected highlighted">...</span>
I was able to locate any of these <span>
s in the browser with this XPath expression:
<code>//span[contains(@class, 'highlighted')]
</code>
<code>//span[contains(@class, 'highlighted')]
</code>
//span[contains(@class, 'highlighted')]
So I tried using that in my Python code:
<code>expect(page.locator("//span[contains(@class, 'highlighted')]")).to_be_visible()
</code>
<code>expect(page.locator("//span[contains(@class, 'highlighted')]")).to_be_visible()
</code>
expect(page.locator("//span[contains(@class, 'highlighted')]")).to_be_visible()
but Pytest complained that the element was not visible. When I printed page.content()
, I didn’t see the highlighted
attributes. I suspected that they might have been dynamically generated (unless I misunderstood how page.content()
was supposed to work).
I was able to select the parent node of these spans both by XPath and via Playwright, but for some reason these elements couldn’t be selected.