Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

TextArea: WebElement.getText() and .getAttribute("value") should be different #2131

@lukeis

Description

@lukeis

Originally reported on Google Code with ID 2131

Hi all,

With 2.1.0, the far below HTML and WebDriver test case works differently with FF 5
/ IE 9 / HtmlUnit 2.8

Output:
IE: 
getText() a,a,                    -> Correct (should it be "a,")
getAttribute() a,a,               -> Correct (should it be "a,")

FF: 
getText()                         -> Incorrect
getAttribute() a,a,               -> Correct (should it be "a,")

HU: 
getText()                         -> Incorrect (due to WebDriver)
getAttribute()                    -> Incorrect (due to HtmlUnit)

Please note that HtmlUnit 2.8 behaves correctly for getText(), but not with getAttribute()
which I will try to fix.


----------------------------------
<html><head><title>foo</title><script>
  function init() {
    var s = document.getElementById('s');
    if (s.addEventListener) {
      s.addEventListener('click', handle, false);
    } else if (s.attachEvent) {
      s.attachEvent('onclick', handle);
    }
  }
  function handle(event) {
    myTextArea.value += s.options[s.selectedIndex].value + ',';
  }
</script></head><body onload='init()'>
  <select id='s'>
    <option value='a'>A</option>
    <option id='opb' value='b'>B</option>
    <option value='c'>C</option>
  </select>
  <textarea id=myTextArea></textarea>

</body></html>
----------------------------------
WebDriver:
        WebDriver driver = ....;
        driver.get(url);
        driver.findElement(By.id("opb")).click();

        WebElement e = driver.findElement(By.id("myTextArea"));
        System.out.println("getText() " + e.getText());
        System.out.println("getAttribute() " + e.getAttribute("value"));
        Thread.sleep(3000);
        driver.close();
----------------------------------
HtmlUnit:
        WebClient webClient = ...;
        HtmlPage page = webClient.getPage(url);
        page.getHtmlElementById("opb").click();

        HtmlTextArea e = page.getHtmlElementById("myTextArea");
        System.out.println("getText() " + e.getText());
        System.out.println("getAttribute() " + e.getAttribute("value"));

Reported by asashour@yahoo.com on 2011-07-26 10:25:03

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions