问题
页面中想定位弹窗中的关闭按钮,但是这个元素被伪元素包围,尝试用By_CSS_SEELECTOR方法和鼠标定位的方式,,都没有成功,鼠标定位后,报错是:
selenium.common.exception.ElementNotInteractableExpection:Message:element not interactable:[object HTMLButtonElement] has no size and location
前端代码如下:
<div class="modal fade poin-eventModal in" id="messageAlertObi" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: block;">
<div class="modal-dialog" style="margin-top:383.5px;">
<div class="modal-content">
<divclass="modal-header">
::before
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<spanclass="modal-title" id="messageAlertInfo">提示信息</span>
::after
pytho代码:
# 方法4:
close_action = ActionChains(self.driver)
ele_close = self.find(By.XPATH,'//*@id="messageAlert0bj"]/div/div/div[1]/button')
close_action.click(ele_close).perform()
报错信息
selenium.common.exception.ElementNotInteractableExpection:Message:element not interactable:[object HTMLButtonElement] has no size and location