python+selenium2自動化---定位元素報錯element click intercepted
阿新 • • 發佈:2020-08-05
頁面元素結構如下圖所示:
通過如下方式獲取該元素後直接點選會報錯:
selenium.common.exceptions.WebDriverException:Message:elementclickintercepted:Element<spanrole="img"id="btn_layer_title_options"tabindex="-1"class="anticoni-moreant-dropdown-trigger">...</span>isnotclickableatpoint(467,22).Otherelementwouldreceivetheclick:<svgwidth="1em"height="1em"fill="currentColor"aria-hidden="true"focusable="false"class="">...</svg>
more_btn = WebDriverWait(self.driver,20,0.5).until(
EC.visibility_of_element_located((By.ID,'btn_layer_title_options'))
more_btn.click()
解決方法:通過執行js指令碼點選該元素
more_btn = WebDriverWait(self.driver,20,0.5).until(
EC.visibility_of_element_located((By.ID,'btn_layer_title_options')
driver.execute_script(" arguments[0].click();", more_btn)