This repository has been archived by the owner. It is now read-only.

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

Open
lukeis opened this Issue Mar 2, 2016 · 4 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

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

@lukeis

This comment has been minimized.

Copy link
Member Author

lukeis commented Mar 2, 2016

To make this even more complex, try selecting 'B' in real InternetExplorer and Firefox.

With InternetExplorer:
- User must click on the parent 'select', and then he can click 'b'. In other words,
you can't have the output to 'b,' manually.

With Firefox:
- User can click directly to 'b,' without the need to click the 'select' first.

Should those differences be considered?

Reported by asashour@yahoo.com on 2011-07-26 10:34:23

@lukeis

This comment has been minimized.

Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by simon.m.stewart on 2011-08-08 07:58:24

  • Labels added: GettingInvolved
@lukeis

This comment has been minimized.

Copy link
Member Author

lukeis commented Mar 2, 2016

What is the meaning of the label "GettingInvolved"?

Reported by mguillemot@yahoo.fr on 2011-08-08 08:02:48

@lukeis

This comment has been minimized.

Copy link
Member Author

lukeis commented Mar 3, 2016

dawagner:

GettingInvolved means this is a good candidate for a bug for someone who wants to start contributing to Selenium to start by looking at, i.e. it's probably not crazily complex, not too huge, and doesn't have much decision-making needed to define the correct answer.

mguillemot@yahoo.fr:

Thanks for the explanation. What about adding a wiki page for the different statii you use for the project's issues?

barancev:

New tests were added by r18247 and r18252
Currently only IE suffers of this issue.
See TextHandlingTest methods testTextOfATextAreaShouldBeEqualToItsDefaultTextEvenAfterTyping and testTextOfATextAreaShouldBeEqualToItsDefaultTextEvenAfterChangingTheValue

@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.