我遇到了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>
有人可以幫我一下吧。
版本: 火狐 - 50.0 硒3.0.0
感謝。
錯誤的'C#'語法在這裏......應該是FindElement和By.Id' –
@PseudoSudo,謝謝你的通知。習慣了Java語法。 –
這沒有奏效。它在文本框中輸入文本,但是當我點擊按鈕時,它顯示強制性警告消息。如果您參考了圖片,您可以看到HTML。在我發佈的代碼中,我已經使用了sendkeys。我用'名字'和'身份證'也嘗試過。這裏的問題是雖然使用sendKeys輸入文本,但它不存儲該值並認爲它是空的。 – Sudeepthi