def twill_xpath_go(browser, original_go):

    from lxml.etree import XPathEvalError
    from lxml.html import document_fromstring

    from twill.errors import TwillException


    def visit_with_xpath(xpath):
        tree = document_fromstring(browser.get_html())

        try:
            result = tree.xpath(xpath)
        except XPathEvalError:
            raise TwillException("Bad xpath" % xpath)

        if len(result) == 0:
            raise TwillException("No match")
        elif len(result) > 1:
            raise TwillException("xpath returned multiple hits! Cannot visit.")

        if not result[0].get("href"):
            raise TwillException("xpath match do not have 'href' attribute")

        response = original_go(result[0].get("href"))
        if browser.result.get_http_code() == 500:
            raise extract_django_traceback(twill=browser)
        else:
            return response
    return visit_with_xpath
Command to run for development environments.
dataset/ETHPy150Open Almad/django-sane-testing/djangosanetesting/utils.py/twill_xpath_go--crossover with--dataset/ETHPy150Open gengo/decanter/decanter/decanter.py/Decanter.runserver