ElementNotVisibleException : 硒 Python [英] ElementNotVisibleException : Selenium Python

查看:50
本文介绍了ElementNotVisibleException : 硒 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查了所有以前的类似问题,它们不适用于我的情况.

I have checked all previous similar issues, they are not applicable to my case.

   try:
      element = wait.until(
      EC.presence_of_element_located((By.XPATH, "//*[@id='_ariaId_73.folder'] | //*[@id='_ariaId_133.folder']"))
   )
   except: 
      print "403 : Monitoring Not Found"

element.click()

它也不会进入异常块,但它仍然为element.click()方法抛出ElementNotVisibleException.

It is not going to enter into exception block also, but it is still throwing ElementNotVisibleException for element.click() method.

推荐答案

关于解决方案的几句话:

A few words about the solution:

  1. 带有子句presence_of_element_located() 的预期条件与检查元素是否存在于页面的DOM 上的预期有关.这并不一定意味着该元素是可见的.用于查找元素的定位器在定位后返回 WebElement.因此,我们必须将子句从 presence_of_element_located() 更改为 visibility_of_element_located(),这将与检查元素的期望相关联,已知存在于页面的 DOM 上,是可见的.可见性意味着元素不仅被显示,而且具有大于 0 的高度和宽度.元素是 WebElement 一旦可见就返回(相同的)WebElement.
  2. 继续前进,您已尝试为 WebElement 调用 click() 方法.因此,我们将使用 element_to_be_clickable() 子句,而不是 presence_of_element_located().
  3. 这是您自己的代码,稍作改动:

  1. Expected conditions with clause presence_of_element_located() relates to an expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible. The locator used to find the element returns the WebElement once it is located. Hence we have to change the clause from presence_of_element_located() to visibility_of_element_located() which relates to an expectation for checking that an element, known to be present on the DOM of a page, is visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. element is the WebElement returns the (same) WebElement once it is visible.
  2. Moving forward you have tried to invoke click() method for the WebElement. So instead of presence_of_element_located() we will use the element_to_be_clickable() clause.
  3. Here is your own code with minor changes :

try:
    element = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='_ariaId_73.folder'] | //*[@id='_ariaId_133.folder']")))
except: 
    print "403 : Monitoring Not Found"
element.click()

这篇关于ElementNotVisibleException : 硒 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆