Modified code to handle xpath selectors