Verify if the element is readonly or disabled I have written a function where it checks if the field is read-only or disabled. However, first it check if that element field is present

This is my working function, but i feel like this is too messy:

def verifyReadOnly(self):
        if self.driver.find_element_by_xpath("//input[@id='cname']"):
            self.driver.find_element_by_xpath("//input[@id='cname' and @readonly='readonly']")
        elif self.driver.find_element_by_xpath("//input[@id='address']"):
            self.driver.find_element_by_xpath("//input[@id='address' and @readonly='readonly']")
        elif self.driver.find_element_by_xpath("//input[@id='address2']"):
            self.driver.find_element_by_xpath("//input[@id='address2' and @readonly='readonly']")
        elif self.driver.find_element_by_xpath("//input[@id='city']"):
            self.driver.find_element_by_xpath("//input[@id='city' and @readonly='readonly']")
        # country
        elif self.driver.find_element_by_xpath("//input[@id='country']"):
            self.driver.find_element_by_xpath("//input[@id='country']/../select[@disabled='disabled']")
        elif self.driver.find_element_by_xpath("//input[@id='state']"):
            self.driver.find_element_by_xpath("//input[@id='state' and @readonly='readonly']")
        elif self.driver.find_element_by_xpath("//input[@id='zip']"):
            self.driver.find_element_by_xpath("//input[@id='zip' and @readonly='readonly']")
        # EIN Custom field
        elif self.driver.find_element_by_xpath("//input[@id='cf_2698238']"):
            self.driver.find_element_by_xpath("//input[@id='cf_2698238' and @readonly='']")
There are several major issues in the code:


violates the DRY principle
there is actually no element presence check - find_element_* method will fail with NoSuchElementException if the element is not found (well, you may be handling the exception outside of the method, but that scatters the logic too much resulting into more "spaghetti code") 


Instead, I would follow the Page Object pattern and build a "Page Element" abstraction, where every element will have the read_only property:

class BasePageElement(object):
    # other methods here

    @property
    def read_only(self):
        elm = self.driver.find_element(*self.locator)
        return bool(elm.get_attribute("readonly"))


class AddressElement(BasePageElement):
    locator = (By.ID, "address")


Note that I'm using the By.ID locator here and the .get_attribute() method as opposed to less readable and more fragile XPath approach.

This, though, does not handle the "element is not present" case properly - you may wrap the .find_element() call with try/except or think of a more generic way to handle it.