Quick

            <span ="buttonContainer"><input type="image" ="helpButton" src="http://sqa.stackexchange.com/images/buttons/btn_help.gif" alt="View  help." title="View  help."><input type="image" ="minimizeButton" src="/businesscare/images/dashboard/btn_minus_white.gif" alt="Show less." aria-controls="tile-contents" aria-expanded="true" aria-live="polite"></span></dt>
            <dd>
                <strong>Help:</strong> Quickly access the tools you need to view your 
                             Name lists.
                        </dd>
        </dl>

        <div ="tile-contents">
            <div><strong>Note:</strong> links open a new window.</div>
            <div ="loading" style="display: none;">
                <div>
                    <p></p>
                </div>
            </div>
            <hr>
            <div ="configuration" style="display: none">
                <p>Choose and drag any transaction type to reorder your
                    shortcuts. Your top five shortcuts will be displayed by default in
                    the shaded area.</p>
                <hr>
                <ul ="dragable">
                </ul>                   
            </div>

            <h4>Links</h4>  
                    <ul ="contents">                       
                        <li><a href="Home" title="View home" onclick="openlink(this,this.title);return false;">View home</a></li>
                    </ul>
                    <hr>
                    <h4 id="Numbers">Numbers</h4>
                    <ul ="contents">                           
                        <li><a href="Link1" onclick="openlink(this,this.title);return false;">View Link1</a></li>
                        <li><a href="Link2" title="View Link2" onclick="openlink(this,this.title);return false;">View Link2</a></li>
                        <li><a href="Link3" title="View Link4" onclick="openlink(this,this.title);return false;">View Link3</a></li>
                    </ul>
                    <hr>

                    <h4 id="Photos">Photos</h4>                         
                    <ul ="contents">
                            <li><a href="Link4" title="Select Link4" onclick="openlink(this,this.title);return false;">Select Link4</a></li>
                        </ul>
                    <hr>

                    <h4 id="downloads">Downloads</h4>
                    <ul ="contents">
                        <li><a href="Link5" title="Download Link5" onclick="openlink(this,this.title);return false;">Download </a></li>
                    </ul>
                    <hr>

                    <h4 id="qlinkusers">Users</h4>
                    <ul ="contents">
                        <li><a href=Link6" title="View Link6" onclick="openlink(this,this.title);return false;">View Users</a></li>
                    </ul>                       
                </div>
    </li>

I need to all the hrefs on the and click them. I tried to the links using the following code but the code returns empty list.

hRefs = []

parent = browser.find_element_by_class_name("contents")

links = parent.find_elements_by_tag_name("a")
for link in links:
    hRefs.append(link)
print hRefs

This is what I get when I run the code an empty list.

[<..remote.webelement.WebElement (session="386157b412d34905ae7344a206c156da", element="0.8337721961119238-2")>]



Source link https://sqa.stackexchange.com/questions/35338/fetch-all-the-links-on-a-page-that-are-within-the-same-class

LEAVE A REPLY

Please enter your comment!
Please enter your name here