fix for adding new element by xpath

used to always add element to end even when that was the incorrect placement