I use Selenium and JUnit4, and I have a form which I want to test for correct alignment.
You can try to use methods getLocation().x
and getLocation().y
of a WebElement.
For example
int id1X = driver.findElement(By.id("id1")).getLocation().x;
int id2X = driver.findElement(By.id("id2")).getLocation().x;
assertEquals(id1X, id2X);
to verify vertical alignment.
You can also play with getSize().height
and getSize().width
to have more complex conditions.