Ejemplo n.º 1
0
def html_modifies_the_html_within_element(conhtml):
    "Element().html('new html') modifies the html string"

    dom = DOM(
        '<div class="drinks">\n'
        '  <h1 id="header">I like marguerita!</h1>\n'
        '</div>'
    )

    h1 = dom.find("div.drinks h1").first()
    assert that(h1.html()).equals('<h1 id="header">I like marguerita!</h1>')

    h1.html('<strong>Yeah, whiskey is much better!</strong>')
    assert that(h1.html()).equals('<strong>Yeah, whiskey is much better!</strong>')
    assert that(h1.text()).equals('Yeah, whiskey is much better!')

    assert that(dom.html()).equals(
        '<div class="drinks">\n'
        '  <strong>Yeah, whiskey is much better!</strong>\n'
        '</div>'
    )
Ejemplo n.º 2
0
def text_modifies_the_text_within_element(context):
    "Element().text('new text') modifies the text content"

    dom = DOM(
        '<div class="drinks">\n'
        '  <h1 id="header">I like piña colada!</h1>\n'
        '</div>'
    )

    h1 = dom.find("div.drinks h1").first()
    assert that(h1.text()).equals("I like piña colada!")

    h1.text('Do you like vodka?')
    assert that(h1.text()).equals("Do you like vodka?")
    assert that(h1.html()).equals('<h1 id="header">Do you like vodka?</h1>')

    assert that(dom.html()).equals(
        '<div class="drinks">\n'
        '  <h1 id="header">Do you like vodka?</h1>\n'
        '</div>'
    )