Home > front end >  playwright python how to get specific texts follwing sibling inner text value
playwright python how to get specific texts follwing sibling inner text value

Time:07-22

I am trying to get the next sibling and next siblings that are in row using the text that occurring in the DOM. but i can't get it by using text that are in DOM

Here i have the selected row's text content, by using the text content i don't know how to get the following-sibling(in td tag) and that sibling's child(in span and small tag).

DOM structure

sibling

sibling's childs

so far i have tried this

    for number in range(len(pan_ids)):
    if (await page.locator(f"text={pan_ids[number]}").is_visible() ==True):
        print(f"pan number : {number}")
        if (await page.locator('td:right-of(:text("{pan_ids[number]}")').is_visible() ==True):
            pass
    else:
        await page.locator('[aria-label="Next page"]').click()
        print(f"pan number : {pan_ids[number]}")

but not getting the result i really don't know where i am lagging. Any help would be appreciated mates

CodePudding user response:

You can use below (Reference).

await page.locator('td > small:below(:text("{pan_ids[number]}")').text_content()

Or, You can also use the Adjacent sibling combinator

await page.locator(':text("{pan_ids[number]}")   td > small').text_content()
  • Related