visibility_of_element_located方法找不到元素时,返回结果不是false
来源:6-8 expected_conditions中元素可见源码分析

慕先生1271423
2019-08-27
试了一下visibility_of_element_located方法的返回结果跟您讲的有点区别,当找不到元素的时候,报了如下的错,而不是返回false
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
2回答
-
慕先生1271423
提问者
2019-08-28
全部代码太长了就给您粘一部分吧
def operation(self,type,oper,location,sendkey):
if(type=='xpath'):
#WebDriverWait(self.driver, 12).until(EC.visibility_of_element_located((By.XPATH,location)))
obj=By.XPATH,location
print(EC.visibility_of_element_located(obj))open_chrome.operation('xpath','click','/html/body/div/div[1]/div[2]/div/div[3]/div/ul/li[1]/ul/li[4]','')
如果找不到控件打印出来的结果就直接是报错信息了
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/div[1]/div[2]/div/div[3]/div/ul/li[1]/ul/li[4]"}
(Session info: chrome=76.0.3809.132)
00 -
Mushishi
2019-08-28
这个有问题,你把代码发一下,这个按照写法讲的一样你的结果不一样?
022019-08-30
相似问题