test_button4 = driver.find_elements_by_class_name('test_button4') # notice its "find_elementS" with an S submit_element = [x for x in test_button4 if x.get_attribute('value') == 'Update'] #this would work if you had unlimited things with class_name == 'test_button4', as long as only ONE of them is value="Update" if len(submit_element): # using a non-empty list as truthiness print ("yay! found updated!")
This is something that I almost never see anyone document, explain or use.
(a bad use name, for example, because its simplest)
find_element_by_name() returns a single element or find_element_by_name() an exception if it does not find it
find_elements_by_name() returns a list of elements. if no items are found, the list is empty.
so if you do find_elements_by_class_name() and it returns a list with X elements in it, all that is left at that point to narrow down what you need is some kind of old-fashioned understanding of the list (for example, as I used in your answer) or some indexing if you for some reason know which element you want.
also get_attribute() also seriously underused. it analyzes the inside of the html elements using what is before = , and returns what after =
source share