0

When I enter details for user name and password and press the submit button, if given information is not valid there is an error message prompt so you have to click on the panel again to re-enter details.

My problem is, I have tried to click on any of the items on panel what obviously I can do manually on the website but not with my automation software because it is giving me an (Element is not clickable) exception. What is the solution for this problem? Any suggestions?

This is html of error message

<div id="msgError" class="col-md-12 text-center">Invalid Last Name!</div>

This is the element I tried to click to close the error message

//Get user name text box element
        var box = Program.Driver.FindElement(By.XPath("//input[contains(@id, 'regFirstName')]"));
        //Click on it
        box.Click();

HTML:

<input class="form-control" data-val="true" data-val-required="The First Name field is required." id="regFirstName" name="FirstName" placeholder="First Name" type="text" value="">
threesixnine
  • 1,733
  • 7
  • 30
  • 56
  • Please post the HTML and your code that you are using to click the element. – Jamie Rees Aug 05 '15 at 09:18
  • @JamieRees Thank you for your comment. The code above has been updated! – threesixnine Aug 05 '15 at 09:35
  • You say, `This is the element I tried to click to close the error message`, can you post the HTML of that? Or are you trying to click on the Error message? – Jamie Rees Aug 05 '15 at 09:36
  • 1
    @JamieRees I am not trying to click on the error message, Because I have to click somewhere else to close the error message. Please take a look at the html code of that element you required. – threesixnine Aug 05 '15 at 09:39

2 Answers2

1

I would suggest that you just use the SendKeys() method rather than just clicking (As I'm going to assume you are sending the username and password)

var username = "your username";
var box = Program.Driver.FindElement(By.Id("regFirstName")); // Lookup using Id

// SendKeys is setting the focus on the field and entering a string
box.SendKeys(username);

Update

If you need to click on the page:

Program.Driver.FindElement(By.XPath("/html/body")).Click();
Jamie Rees
  • 7,973
  • 2
  • 45
  • 83
  • Maybe I didn't explain my problem very well. I don't have a problem with adding input to a box , I have a problem with unlocking the screen where I am supposed to enter my input after error message prompts. Because the only way of removing the error message is by clicking somewhere else on the page, probably you've seen that method before. – threesixnine Aug 05 '15 at 09:45
1

You need to add a new action to your code that does box.Click(). You could also try adding .Perform() after but I do not think that will work.

I believe this is the snippet of code you need:

new Actions(driver).moveToElement(box).click().perform();

Which I grabbed from here

Community
  • 1
  • 1
Jamie Babineau
  • 746
  • 2
  • 12
  • 25