简体   繁体   中英

The button does not click I have used javascript and and the Actions syntax

I am automating filling out a form, once filled there is an update button but it doesn't click it just changes colour. This shows I have the xpath correct.

I have tried two things javascript scrollinto view and click and also the Actions perform code. They both work to the extent of changing the button colour but it does not click. I have tried this:

IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].scrollIntoView(true);",element);
executor.ExecuteScript("arguments[0].click();", element);

and I have tried this:

Actions builder = new Actions(driver);
builder.MoveToElement(_regRep.btnUpdateOrganization)
       .Click()
       .Build()
       .Perform();

The expected results is to simply click the button

It might be the case that the element is not interactable by its nature (ie Selenium fills form too fast and button which is initially disabled doesn't receive the corresponding JavaScript event indicating that all mandatory fields are filled and it can be clicked)

I would recommend using Explicit Wait approach , to wit introduce WebDriverWait class and configure it via Expected Conditions . Once done you will be able to use IWebElement.Click() method so if the click fails - Selenium should inform you regarding what went wrong.

Example WebDriverWait usage:

var clickableEmenent = (new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(element)));
clickableEmenent.Click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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