简体   繁体   English

该按钮没有单击我已经使用了javascript和Actions语法

[英]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.

相关问题 Selenium 不点击按钮,即使使用 javascript - Selenium does not click on a button, even when javascript is used 按钮单击时发生 2 个操作 javascript - Having 2 actions occur on button click javascript 在javascript验证中,我必须单击两次提交按钮 - in javascript validation i have to click submit button twice 我必须单击两次按钮才能触发事件处理程序 - I have to click a button twice for an event handler to fire javascript Javascript中的“下一步”按钮和使用JavascriptExecutor单击“下一步”按钮,但它对我没有帮助 - “Next” Button in Javascript & used JavascriptExecutor to click on “next” button but it does not help me out 每次单击 Javascript 中的单个按钮时,我可以创建最多 5 个不同的操作吗? - Can I create up to 5 different actions on each click on a single button in Javascript? 按钮单击动作的Javascript(jQuery)语法 - Javascript (jQuery) Syntax on button click action 我想在每个按钮单击事件上加载多个图表。 - I want to load multiple charts on every button click event.I have used below google code 单击按钮不会触发JavaScript - JavaScript does not fire on click of button 当我有时点击购物按钮时,它不起作用 javascript - When I Sometimes click on shopping button , it does not work javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM