Search code examples
pythonhtmlseleniumwebdriver

Checking that none of the html inputs should visually interfere with each other selenium python


Is there any way to checking if html inputs interfere each other visually selenium python? For example below image has overlapping elements:

enter image description here

And second below image has no ovarlapping elements:

enter image description here

I want to check this in some different web page sizes like 800*600 and 1024*768.


Solution

  • You can get get location and size properties of each relevant element and calculate if there are interferences or not.
    Like this:

    driver = webdriver.Firefox()
    
    e = driver.find_element_by_xpath("//someXpath")
    
    location = e.location
    size = e.size
    w, h = size['width'], size['height']
    
    print(location)
    print(size)
    print(w, h)
    

    The output here will be something like this:

    {'y': 202, 'x': 165}
    {'width': 77, 'height': 22}
    77 22