Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Selenium中选择此下拉按钮?_Python_Selenium - Fatal编程技术网

Python 如何在Selenium中选择此下拉按钮?

Python 如何在Selenium中选择此下拉按钮?,python,selenium,Python,Selenium,我有这个html: <div class="dropdown float-right"> <button class="btn btn-default" type="button" id="export-button" data-toggle="dropdown"> <i class="the-download-export"

我有这个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>

出口
下载文件
这是一个有几个选项的下拉列表。单击按钮时,它会折叠下拉选择并显示div(为简单起见,这里没有添加更多用于各种数据格式的div)

我尝试了一些方法来单击csv数据格式的按钮,但都失败了。要么找不到它,要么只获取div,这是不可交互的


在Python中,选择和单击此下拉可折叠按钮的正确方式是什么?

这方面的工作很少

我建议您检查是否可以通过其他方式获取数据(例如,单击按钮时调用api),或者使用类似x-path的方法

button = getFromXPath(".//button[@id='export-button']")
button.click()

不幸的是,没有API,我可以代理流量,但我真的想避免这种情况,这就是我选择selenium的主要原因。到目前为止,除了这个下拉按钮,我已经能够使一切正常工作。真奇怪。我会尝试你的建议,现在会让你知道,谢谢!这实际上几乎奏效了。它基本上折叠了下拉列表,并向我展示了选择div(“下载为CSV”、“下载为EXCEL”)等。。现在看起来需要再次单击折叠的div,但可能需要折叠选择器的第一步。我会看看我是否能想出第二个点击选择器,这看起来很接近。如果你有任何想法,请让我知道,谢谢!我得到了它!它需要两次点击,看起来像。一旦我使用了你的点击,它看起来就像它使div点击可交互。现在很有魅力,谢谢!很乐意帮忙:)