How do I select this dropdown button in Selenium?

Tags: ,

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>
    <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 ?


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']")

Source: stackoverflow