【发布时间】:2018-04-19 12:27:37
【问题描述】:
设置
我正在使用 Python 3.x 和 Selenium 填写查询字段,然后单击搜索按钮,
# 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).
问题
执行上面的代码会出现以下错误,
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
我可以通过在抓取并单击按钮之前插入一个硬等待来解决此错误,就像这样,
# click search button
time.sleep(1)
search_area.find_element_by_xpath('span/a[1]').click()
但我宁愿用不同的方式解决它,所以我跟着this answer做了以下,
# 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()
但我得到了完全相同的错误。
我也试过this answer,但同样的错误。
我该如何解决这个问题?
【问题讨论】:
-
感谢 DebanjanB!最后nr.5做到了!
wait.until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='blockUI blockOverlay']")))然后el_xp("//input[@value='Save']").click()。