Skip to content
Advertisement

How do I select this dropdown button in Selenium?

I have this html :

<div class="dropdown float-right">
    <button class="btn btn-default" type="button" id="export-button" data-toggle="dropdown">
        <i class="the-download-export"></i>
                Export
    </button>
    <div class="dropdown-menu dropdown-menu-right"><div class="dropdown-item action-export" data-format="csv" data-store="com" data-reverse-type="single"><i class="text-primary fa fa-upload" aria-hidden="true"></i>Download File</div>

This is a dropdown that has a few options. When the button is clicked, it collapses the dropdown selection and the divs appear(there are more divs for various data formats which i haven’t added here for simplicity).

I have tried a few things in order to click the button with the csv data format, but everything has failed. Either not finding it or getting the div only, which is not interactible.

What is the proper way of selecting and clicking this dropdown collapsible button in Python ?

Advertisement

Answer

That’s very little to work on.

I can recommend either checking whether you can get the data another way (e.g. api call when clicking the button) or something with x-path like

button = getFromXPath(".//button[@id='export-button']")
button.click()
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement