Reputation: 478
I have an issue regarding a textbox that I can't seem to get selenium to click and enter text. It's a password box for a website. The Username part is fine but for whatever reason I cant send text to the password box. I get the error message "Element is not currently visible and so may not be interacted with"
I have tried several different methods for locating the textbox such as XPath name,contains, id etc but nothing will seem to work. Any ideas? I have also tried a wait and an waitforelement. Also I have returned all the element names "tbPassword" to see if there is a conflict and it only returns 1.
Here is my code:
driver.Navigate().GoToUrl("http://www.paddypower.com/bet");
IWebElement clickUsername = driver.FindElement(By.XPath("//input[@name='tbUsername']"));
clickUsername.Click();
clickUsername.SendKeys("MyUsername");
IWebElement clickPassword = driver.FindElement(By.XPath("//input[@name='tbPassword']"));
clickPassword.Click();
clickPassword.SendKeys("Mypassword");
Upvotes: 2
Views: 3915
Reputation: 17
I was also facing the same issue and when I saw this post it helped me to find out the real issue but in my case there was two controls with the same names "username" and "password" and system was throwing an exception when I wanted to use the control.SendKeys after finding the control so I used the below code to resolve the issue.
allTextBoxes = driver.FindElements(By.Id("username"));
var allPasswordTextBoxes = driver.FindElements(By.Id("password"));
var userNameTextField = allTextBoxes.Count > 0 ? allTextBoxes[1] : allTextBoxes[0];
userNameTextField.SendKeys("myUsername");
var passwordTextField = allPasswordTextBoxes.Count > 0 ? allPasswordTextBoxes[1] : allPasswordTextBoxes[0];
passwordTextField.SendKeys("myPassword");
Upvotes: 0
Reputation: 473863
There is a duplicate password input
that is actually visible:
<div class="inputbg">
THIS IS VISIBLE => <input id="dummypassword" class="input" type="text" onfocus="this.style.display='none';document.getElementById('pw').style.display='inline';document.getElementById('pw').focus()" value="Password" tabindex="2" name="dummypassword">
THIS IS INVISIBLE => <input id="pw" class="input" type="password" onblur="if(this.value==''){this.style.display='none';document.getElementById('dummypassword').style.display='inline'}" onkeypress="if (event.keyCode==13)fmLogin.submit();" value="" style="display: none;" tabindex="2" name="tbPassword" autocomplete="off">
</div>
After you click the visible "dummy" input, it becomes invisible and the "tbPassword" input is becoming visible instead. Follow this behavior in your code:
IWebElement clickPassword = driver.FindElement(By.Id("dummypassword"));
clickPassword.Click();
IWebElement realPasswordInput = driver.FindElement(By.XPath("//input[@name='tbPassword']"));
realPasswordInput.SendKeys("Mypassword");
Upvotes: 2