Reputation: 3575
I'm trying to test my GWT application using selenium, the html generated by GWT Textbox is shown as below:
<input type="text" class="gwt-TextBox" >
No value there, but from UI i can see the text, Is there a way to get the value from selenium?
UPDATE: I can locate the input
from selenium, but can not get its value, for example the value of above input
is "blahblah...", which i can see from page UI, but can't get from the above html.
Upvotes: 0
Views: 2298
Reputation: 9837
If you want the resulting DOM to look like
<input type="text" class="gwt-TextBox" value="myValue">
you'll have to use
textBox.getElement().setAttribute("value", "myValue");
instead of
textBox.setText("myValue")
That's because setText
will only update the value
property (i.e. theDomElement.value = "myValue"
), which will not update the value
attribute (i.e. <input value="myValue"/>
).
When updating a property, the browser will not update the associated attribute.
Upvotes: 0
Reputation: 66
Like @BMT said, you should get the value using getAttribute, like this
GWT Code
TextBox textField = new TextBox();
textField.ensureDebugId("textFieldId");
Selenium Code
driver.findElement(By.id("textFieldId")).getAttribute("value");
You could see all the properties (visible or invisible) of one element using Inspect Element Tool of browsers (F12), then get the value you want.
Upvotes: 1
Reputation: 9570
@Bhumika is correct, having a unique id
attribute for every element you would want to manipulate is good programming practice. But if you don't have that and can't get it added, you still have a good handle on this particular case: the placeholder
attribute. To locate the element, use the XPath //input[@placeholder='Input note title...']
. To obtain the value of the field, get its value
attribute.
Upvotes: 1
Reputation: 7630
Each widget should have a id for selenium testing. Here selenium does not identify element, and you are not able to get value which are on UI. so you have to set id for input widget. i.e
TextBox textField= new TextBox();
textField.getElement().setId("name");
Upvotes: 0