Firefoxが必須フィールドであるテキストボックス(ポップアップ内)にテキストを入力する状況が発生しました。ボタンをクリックすると、警告フラグが表示されます。 HTMLをチェックすると、テキストボックスには値が表示されず、HTML表示フィールドにはtitle
というフィールドが必要です。Firefoxがテキストボックスに入力したテキストを認識しない
JavaScriptを使用してテキストを入力しようとしましたが、役に立たなかった。
コードスニペット:テキストボックスのため
public static void UserName(string text)
{
try
{
IJavaScriptExecutor js = (IJavaScriptExecutor)Drivers._driverInstance;
IWebElement element = Drivers._driverInstance.FindElement(By.Id("newName"));
//js.ExecuteScript("document.getElementById('newName').setAttribute('value', '" + text + "')");
js.ExecuteScript("arguments[0].click();", element);
js.ExecuteScript("document.getElementById('newName').value='" + text + "';");
//Drivers._driverInstance.FindElement(By.Name("newName")).Clear();
//Drivers._driverInstance.FindElement(By.Name("newName")).SendKeys(text);
}
catch(Exception e)
{
throw new Exception("Couldn't send text to username textbox " + e);
}
}
HTML:
<div class="field-container">
<label>Username</label>
<input id="newName" class="input-validation-error" name="newName" data-bind="value: Name" title="This field is required." data-orig-title="This field is required." type="text"/>
<span class="validationMessage" style="">This field is required.</span>
誰かがそれで私を助けることができます。
バージョン: Firefoxの-50.0 セレン-3.0.0
感謝。次のように
ここで間違った 'C# '構文は、' FindElement'と 'By.Id'です。 –
@PseudoSudo、通知してくれてありがとうございます。 Javaの構文に慣れてしまった。 –
それは動作しませんでした。テキストボックスにテキストが入力されましたが、ボタンをクリックすると警告メッセージが表示されます。画像を参照すると、HTMLが表示されます。私が投稿したコードでは、私はすでにsendkeysを使っていました。私は '名前'と 'Id'でも試してみました。ここの問題は、テキストがsendKeysを使用して入力されても、値を格納せずに空であると思うことです。 – Sudeepthi