2013-04-10 6 views
24

tôi có thể nhìn thấy trong tài liệu hướng dẫnTrong selen trăn, làm thế nào để tìm thấy khả năng hiển thị của một phần tử?

http://selenium.googlecode.com/svn/trunk/docs/api/py/selenium/selenium.selenium.html#selenium.selenium.selenium.is_visible

phương pháp is_visible, nhưng tôi không có ý tưởng làm thế nào để sử dụng nó. Tôi tiếp tục nhận được lỗi như "is_visible cần một ví dụ selen như tham số đầu tiên", cũng là một "định vị" là gì?

Mọi trợ giúp sẽ được đánh giá cao.

Trả lời

53

Bạn nên sử dụng is_displayed() thay vì:

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"