【发布时间】:2020-11-16 22:09:21
【问题描述】:
我的前端有一个下拉菜单,如下所示:
<div class="dropdown-menu dropdown-menu-right text-left" id="dropdown_menu">
<a class="dropdown-item" data-toggle="modal" data-target="#exampleModalCenter" id="dropdown_change_pwd">Change Password</a>
<a class="dropdown-item" href="{{ url_for('auth.logout') }}" id="dropdown_logout">Logout</a>
</div>
我想在 python 中使用 selenium 访问这些按钮。我尝试这样访问它:
class SearchPage:
_CHANGE_PWD_DROPDOWN = (By.ID, 'dropdown_change_pwd')
_LOGOUT_DROPDOWN = (By.ID, 'dropdown_logout')
_DROPDOWN = (By.ID, 'dropdown_menu')
def __init__(self, browser):
self.browser = browser
def logout(self):
time.sleep(5)
dropdown = self.browser.find_element(*self._DROPDOWN)
dropdown.click()
logout = self.browser.find_element(*self._LOGOUT_DROPDOWN)
logout.click()
但我总是以:
response = {'status': 400, 'value': '{\n\t"value" : \n\t{\n\t\t"error" : "element not interactable",\n\t\t"message" : "Element is not displayed",\n\t\t"stacktrace" : ""\n\t}\n}\r\n'}
Selenium 似乎无法处理引导下拉菜单。我怎样才能仍然单击此下拉列表中的任何元素?
如果没有直接的解决方案,是否有解决方法?
【问题讨论】:
标签: python selenium bootstrap-4