我找到了is_visible
method in the Selenium documentation,但我不知道如何使用它。我不断收到is_visible needs a selenium instance as the first parameter
等错误。
另外,什么是“定位器”?
任何帮助都将不胜感激。
答案 0 :(得分:74)
您应该使用is_displayed()
代替:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.google.com')
element = driver.find_element_by_id('gbqfba') #this element is visible
if element.is_displayed():
print "Element found"
else:
print "Element not found"
hidden_element = driver.find_element_by_name('oq') #this one is not
if hidden_element.is_displayed():
print "Element found"
else:
print "Element not found"
答案 1 :(得分:0)
只需使用
selenium.webdriver.support.expected_conditions.visibility_of
cos
可见性意味着该元素不仅显示,而且具有 高度和宽度大于0