[英]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.
这表明我有正确的xpath。
I have tried two things javascript scrollinto view and click and also the Actions perform code. 我已经尝试了两个javascript scrollinto查看和点击的东西以及Actions执行代码。 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) 情况可能是元素本身不可交互(即Selenium填充形式太快,最初禁用的按钮不会收到相应的JavaScript事件,表明所有必填字段都已填充且可以单击)
I would recommend using Explicit Wait approach , to wit introduce WebDriverWait class and configure it via Expected Conditions . 我建议使用显式等待方法 ,介绍WebDriverWait类并通过预期条件进行配置。 Once done you will be able to use IWebElement.Click() method so if the click fails - Selenium should inform you regarding what went wrong.
完成后,您将能够使用IWebElement.Click()方法,因此如果点击失败 - Selenium应该告知您出了什么问题。
Example WebDriverWait usage: 示例WebDriverWait用法:
var clickableEmenent = (new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(element)));
clickableEmenent.Click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.