0

I am trying to parse this code on selenium and basically want the first item from the list i.e "product one-col new"! clicked...

<ul id="product-list">

    <li class="product one-col new">
        <ul>
            <li class="image" title="one item 5">
                <a href="#product/0f37f703-ed9a-3d10-86c0-7d0c0fcdb9ec">
                    <img width="" height="" alt="" src="/content/images/ProductImages/you-are-here/3/E/4/3E42561208174E6FBC81A10CDAE48659.jpg"></img>
                    <span class="new"> … </span>
                    <span class="hover"></span>
                </a>
                <p class="retailer">

                    CHECK ME

                </p>
                <p class="brand"></p>
            </li>
            <li class="price"> … </li>
            <li class="name" title="one item 5"> … </li>
            <li class="first-seen"> … </li>
        </ul>
    </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>

I have tried this

browser.find_element_by_css_selector("ul[id='product-list']  li:nth-of-type(1)").click()

but it does not work?

any idea?

UPDATE:

the correct path was

browser.find_element_by_css_selector("ul#product-list > :first-child").text

1 Answer 1

2

Looks like you want a direct child, so the selector should use the child combinator. Plus, there’s :first-of-type/:first-child:

#product-list > :first-child
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.