Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In python selenium, how does one find the visibility of an element?

I found the is_visible method in the Selenium documentation, but I have no idea how to use it. I keep getting errors such as is_visible needs a selenium instance as the first parameter.

Also, what is a "locator"?

Any help would be appreciated.

like image 870
user2183536 Avatar asked Apr 10 '13 22:04

user2183536


People also ask

How do you check if an element is visible on the web page in Selenium Python?

We can also verify if an element is present in the page, with the help of find_elements() method. This method returns a list of matching elements. We can get the size of the list with the len method. If the len is greater than 0, we can confirm that the element exists on the page.


1 Answers

You should use is_displayed() instead:

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" 
like image 56
rcdsystems Avatar answered Sep 22 '22 07:09

rcdsystems