简体   繁体   English

Firefox无法识别在文本框中输入的文本

[英]Firefox doesn't recognise the text that it entered in textbox

I came across a situation where Firefox enters the text in the textbox(within a popup) which is a mandatory field. 我遇到了Firefox在文本框(在弹出窗口中)输入文本的情况,该文本框是必填字段。 When I click on the button, it shows the warning flag. 当我单击按钮时,它显示警告标志。 When I checked the HTML, it shows that there is no value in the text box and title in HTML shows field is required. 当我检查HTML时,它表明文本框中没有任何值,并且“ HTML显示”字段中的title为必填字段。

I tried using JavaScript to enter the text but it didn't help. 我尝试使用JavaScript输入文本,但没有帮助。

Code Snippet: 代码段:

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 for textbox: 文本框的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>

图片供参考

Can someone help me with it. 有人可以帮我吗。

Version: Firefox-50.0 Selenium-3.0.0 版本:Firefox-50.0 Selenium-3.0.0

Thanks. 谢谢。

尝试如下:

driver.findElement(By.Id("newName")).sendKeys(text);

Try this: 尝试这个:

var username = "User Name Here";
driver.FindElement(By.Id("newName")).sendKeys(username);

I would switch to ChromeDriver for now. 我现在将切换到ChromeDriver。 I do not think webdriver 3.0 is working well with Firefox v50. 我认为webdriver 3.0无法在Firefox v50上正常运行。 If you must use firefox, drop down a version and go to a previous version of webdriver. 如果必须使用Firefox,请下拉一个版本并转到Webdriver的早期版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM