【问题标题】:The button does not click I have used javascript and and the Actions syntax按钮未单击我使用了 javascript 和 Actions 语法
【发布时间】:2019-10-21 22:57:43
【问题描述】:

我正在自动填写表格,填写后会有一个更新按钮,但它不点击它只是改变颜色。这表明我的 xpath 正确。

我尝试了两件事 javascript scrollinto view 和 click 以及 Actions 执行代码。他们都在改变按钮颜色的范围内工作,但它没有点击。 我试过这个:

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

我已经试过了:

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

预期的结果是简单地点击按钮

【问题讨论】:

    标签: javascript c# google-chrome selenium-webdriver


    【解决方案1】:

    这可能是元素本质上不可交互的情况(即 Selenium 填充表单的速度太快,并且最初禁用的按钮没有收到相应的 JavaScript 事件,指示所有必填字段都已填写并且可以单击)

    我建议使用Explicit Wait approach,以引入WebDriverWait 类并通过Expected Conditions 配置它。完成后,您将能够使用IWebElement.Click() method,因此如果单击失败 - Selenium 应该会通知您出了什么问题。

    WebDriverWait 用法示例:

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

    【讨论】:

    • ExpectedConditions 已被弃用,如何解决?
    猜你喜欢
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 2012-06-11
    相关资源
    最近更新 更多