silhouette hustler
silhouette hustler

Reputation: 1763

Element not clickable selenium c#

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="">

Upvotes: 0

Views: 2795

Answers (2)

Jamie Babineau
Jamie Babineau

Reputation: 756

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

Upvotes: 1

Jamie Rees
Jamie Rees

Reputation: 8183

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();

Upvotes: 1

Related Questions