webdriver中,is_displayed()用来判断元素是否可见!
webdriver中,is_displayed()用来判断元素是否可见,返回True or False,但是如果元素不可见,就直接报错,这还怎么判断不可见的元素呢?driver = webdriver.Chrome()driver.get('https://www.baidu.com')
aa = driver.find_element_by_id('123')
if aa.is_displayed():
print('1')
else:
print('2')
driver.quit()错误信息,定位不到元素:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":""}
(Session info: chrome=93.0.4577.82)
不可见和不存在是两个概念 隐藏元素才会有可见不可见 确认是否有先
页:
[1]