I have a dialog with several different input fields and types where I want to check according to the written name in front of the input field if the field is
- presented
- readonly
The difficulty is that I have differnt types of input I want to check:
- input
- textarea
- div
- select
So the HTML is simply like:
<tr>
<td>Name</td>
<td><input ...></td>
</tr>
<tr>
<td>Gender</td>
<td><select ...></td>
</tr>
<tr>
<td>information</td>
<td><textarea ...></td>
</tr>
...and so on...
My method gets only the name in front of the field and if it should be presented and readonly:
public boolean checkIfPresentedAndReadonly(String field, boolean present, boolean readonly){
boolean result = false;
try{
WebElement element = find(By.xpath("//tr[td[@class='c1'][label[text()[contains(.,'"+field+"')]]]]/td[@class='c2']/div/*"));
result = (checkForReadOnly(element) == readonly);
}catch(NoSuchElementException e){
return !present;
}
return result;
}
My xpath returns any type (could be div, select, input etc.).... is there a nice way to find out the type of the WebElement
? I thought about looking up the type and then doing some if/else statements to check the state depending on the input type like for type <input>
I would check if it is possible to do a clear()
and sendKeys("..")
and then read the input so I can be sure that the element is writable.
Or are they any other possible solutions?