硒无法单击元素,因为其他元素将其遮盖了 [英] Selenium can't click element because other element obscures it
问题描述
设置
我正在使用Python 3.x和Selenium填写查询字段,然后单击搜索按钮,
I'm using Python 3.x and Selenium to fill out a query field and subsequently click the search button,
# element containing the product search bar and buttons
search_area = el_id('Products').find_element_by_class_name('searchArea')
# insert name of file to be duplicated
name_field = search_area.find_element_by_xpath("//input[@type='text']")
name_field.clear()
name_field.send_keys('to_be_duplicated')
# click search button
search_area.find_element_by_xpath('span/a[1]').click()
其中 el_id(x)= browser.find_element_by_id(x)
.
问题
执行上面的代码会产生以下错误,
Executing the code above gives the following error,
ElementClickInterceptedException: Element <a class="button button-fleft searchButton" href="#"> is not clickable at point (577.6166763305664,225.06666564941406) because another element <div class="blockUI blockOverlay"> obscures it
我可以通过在抓住并单击按钮之前插入一个硬等待来解决此错误,
I can solve this error by inserting a hard wait before grabbing and clicking the button, like so,
# click search button
time.sleep(1)
search_area.find_element_by_xpath('span/a[1]').click()
但是我宁愿以不同的方式解决它,所以我遵循了这个答案,并做了以下
But I rather solve it differently, so I followed this answer and did the following,
# click search button
search_button = search_area.find_element_by_xpath('span/a[1]')
WebDriverWait(driver, 10).until_not(EC.visibility_of_element_located((By.XPATH,
"//*[@id="Products"]/tbody/tr[1]/td/div/input")))
search_button.click()
但是我得到了完全一样的错误.
But I got exactly the same error.
我还尝试了此答案,但存在相同的错误.
I also tried this answer, but same error.
我该如何解决?
推荐答案
按照 DebanjanB的答案中的第5条,通过暗示代码在尝试单击之前等待临时叠加层消失来解决此问题,
Following nr.5 of DebanjanB's answer, I solved it by implying the code to wait for the temporary overlay to dissapear before trying to click,
wait.until(EC.invisibility_of_element_located((By.XPATH,
"//div[@class='blockUI blockOverlay']")))
el_xp("//input[@value='Save']").click()
这篇关于硒无法单击元素,因为其他元素将其遮盖了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!