0

I want to test my vaadin component automatically but to do that I have to somehow get and set value into corresponding element. Normally in HTML DOM you see it like this:

<textarea rows="4" cols="50">
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. 
</textarea>

but in vaadin:

<input type="text" class="v-textfield v-widget v-has-width" id="first-name-text-field" aria-labelledby="gwt-uid-40" tabindex="0" style="width: 250px;">

yet this element could contain the same text as the textarea above.

I am missing something and cannot find where I should get/set methods. Googling didn't help, official documentation didn't seem to hahve anything on the matter. At this point I'm confused.

ps: if it helps I want to test it with Selenium, but I think it's unrelated. I would like to answer any and all question that would point me to the right direction. Thanks.

pss: Maybe there actually is method in java-selenium to getValue() of element and I do not need this dom?

Andrii Plotnikov
  • 3,022
  • 4
  • 17
  • 37
  • Best go via the ID `id="first-name-text-field"` – André Schild May 24 '16 at 09:43
  • sorry if you misunderstood. I don't want to get some element (I can do that), but I want to put/get value into element. In vaadin element, for which I do not understand how it's values stored/retrieved. – Andrii Plotnikov May 24 '16 at 10:21
  • You are using Selenium. I would guess it is just the same as without Vaadin: `driver.findElement(By.id("first-name-text-field")).sendKeys("test");` – Steffen Harbich May 24 '16 at 10:52
  • Its input type text.... – André Schild May 24 '16 at 11:08
  • @SteffenHarbich yes, for inputing. How do i retrieve what's inside? i.e. getValue() or smth. – Andrii Plotnikov May 24 '16 at 11:42
  • I am not sure whether I understand your question correctly. Do you want to retrieve value of the input text component during the Selenium test or during the runtime? I think Selenium expose api that can check whether the element contains certain value. – kukis May 24 '16 at 12:03
  • 1
    @Sarief should be `getText()` or `getAttribute("value")` on the `WebElement`. I guess the latter one will work. – Steffen Harbich May 24 '16 at 12:08
  • @SteffenHarbich, getAttr by "value" actually worked. Don't know why I didn't find it by myself. thank you. – Andrii Plotnikov May 25 '16 at 12:07

1 Answers1

1

Once you have set the ID to the component via setId, you can use Selenium as usual. For text inputs you can then call

driver.findElement(By.id("your-id")).getAttribute("value")

to get the value entered by user. See also this answer.

Community
  • 1
  • 1
Steffen Harbich
  • 2,639
  • 2
  • 37
  • 71