I’m not getting the expected value returned from the below code.
from playwright.sync_api import sync_playwright
import time
import random
def main():
with sync_playwright() as p:
browser = p.firefox.launch(headless=False)
page = browser.new_page()
url = "https://www.useragentlist.net/"
page.goto(url)
time.sleep(random.uniform(2,4))
test = page.locator('xpath=//span[1][@class="copy-the-code-wrap copy-the-code-style-button copy-the-code-inside-wrap"]/pre/code/strong').inner_text()
print(test)
count = page.locator('xpath=//span["copy-the-code-wrap copy-the-code-style-button copy-the-code-inside-wrap"]/pre/code/strong').count()
print(count)
browser.close()
if __name__ == '__main__':
main()
page.locator().count() returns a value of 0, I have no issue getting the text from the lines above it, but I need to access all elements, what is wrong with my implementation of locator and count?