This seems to be doing the element scan twice. I would extract a variable from getDriver().findElements(By.id("container")) and check it size is greater than 0 then get the first element out of the list.