How to validate that an object (whose locator we don't know since it is not present) is not present in a page



  • Let's say I want to verify that an upload button is not present in a page. I cannot use any locator here since I don't know the object locator value. So how do I assert in my test that it is never present?



  • Normally "upload button" is a HTML input of type file which looks like:

    <input type="file" ...... >
    

    So you need to verify whether at least 1 input of type file is present at the page. It can be done using the following XPath selector:

    //input[@type='file']
    

    Example code (Python)

    file_upload_elements = driver.find_elements_by_xpath("//input[@type='file']")
    
    if (len(file_upload_elements) > 0):
        print('File upload input is present')
    else:
        print('File upload input is absent')
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2