入力フィールドの前に書かれた名前に従って、フィールドが
- 提示された
- 読み取り専用
難しいのは、確認したい入力の種類が異なることです。
- 入力
- テキストエリア
- 分周
- 選択する
したがって、HTML は単純に次のようになります。
<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...
私のメソッドは、フィールドの前にある名前のみを取得し、それを提示して読み取り専用にする必要がある場合:
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;
}
私のxpathは任意のタイプを返します(div、select、inputなどの可能性があります)....のタイプを見つける良い方法はありWebElement
ますか?タイプを調べてから、入力タイプに応じて状態を確認するためにいくつかの if/else ステートメントを<input>
実行することclear()
をsendKeys("..")
考えました。要素は書き込み可能です。
または、他の可能な解決策はありますか?