OptimusAutomation
OptimusAutomation

Reputation: 151

Selenium locator how do I locate a list of child div class attribute tags

I am trying to locate a list of child div class tags. When I inspect element in Chrome the following Xpath I have tried is not selecting all the elements I want.
On the page there are 5 tabs shown. I want to get all these 5 elements into a list so I can use a For Each loop to iterate over the elements

I want to locate all these tabs

<div class="jsx-1429490698 Tab Tab_active Tab_sports">sports</div>
<div class="jsx-1429490698 Tab  Tab_casino">casino</div>
<div class="jsx-1429490698 Tab  Tab_liveCasino">live &amp; real</div>
<div class="jsx-1429490698 Tab  Tab_esports">esports</div>
<div class="jsx-1429490698 Tab  Tab_vegas">vegas</div>

My Xpath is

//div[@id='__next']//following-sibling::div[contains(@class, 'Tab')]

I decalare the locator as

[FindsBy(How.Xpath, Using="//div[@id='__next']//following-sibling::div[contains(@class, 'Tab')]")]
private IList<IWebElement> PromotionBrandTabsListElement {get; set;}

In Chrome when trying this Xpath locator in it is first highlighting

<div class="jsx-1350237217 Tabs__container">

and then it highlights

<div class="jsx-1429490698 Tab  Tab_casino">casino</div>

I want it to highlight Sports, Casino, LiveCasino, esports and vegas I would like all these into a list element

The HTML structure is

<div id="__next">
<div class="jsx-2794910414 top">
    <div class="jsx-133833352 Promotions__container">
        <div class="jsx-1850983400 Title__container">
            <div class="jsx-1850983400 Title__text--container">
                <div class="jsx-1850983400 Title__text">Promotions</div>
            </div>
        </div>
        <div class="jsx-1350237217 Tabs__container">
            <div class="jsx-1429490698 Tab Tab_active Tab_sports">sports</div>
            <div class="jsx-1429490698 Tab  Tab_casino">casino</div>
            <div class="jsx-1429490698 Tab  Tab_liveCasino">live &amp; real</div>
            <div class="jsx-1429490698 Tab  Tab_esports">esports</div>
            <div class="jsx-1429490698 Tab  Tab_vegas">vegas</div>
        </div>
        <div class="jsx-3650671054 jsx-3221847745 Promotion">
    </div>
</div>

How do I just get Sports, Casino, LiveCasino, esports and vegas tabs please.

Thanks

Upvotes: 1

Views: 300

Answers (1)

Jack Fleeting
Jack Fleeting

Reputation: 24930

Try changing your xpath expression to

//div[@id='__next']//div[contains(@class, 'Tabs__container')]//div[contains(@class, 'Tab')]

and see if it works.

Upvotes: 1

Related Questions