【问题标题】:Button was not actually clicked but shows element.click() performed in selenium script按钮实际上没有被点击,但显示在 selenium 脚本中执行的 element.click()
【发布时间】:2020-08-18 00:12:35
【问题描述】:

我正在为 Pega Web 应用程序编写自动化脚本。我有按钮点击功能,但实际上当我运行脚本时按钮没有被点击。当我检查日志时,它显示操作已执行,但实际上并没有点击按钮。

我尝试了以下操作,但没有任何效果,

WebDriverWait wait = new WebDriverWait(driver, 80);
            wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Submit')]")));

driver.findElement(By.xpath("//button[contains(text(),'Submit')]")).click();

然后我尝试了下面的代码,

WebDriverWait wait = new WebDriverWait(driver, 80);
            wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Submit')]")));

WebElement button=driver.findElement(By.xpath("//button[contains(text(),'Submit')]"));

button.sendKeys(Keys.RETURN);

我也试过javascript,

JavascriptExecutor jse = (JavascriptExecutor) driver;
    jse.executeScript("arguments[0].click();", button);

【问题讨论】:

  • 你尝试过动作课吗?
  • 不,我没试过。我也会检查一下。
  • @AmrutaPande,我试过了,但我得到了 org.openqa.selenium.StaleElementReferenceException: exception
  • 你如何断言它没有点击按钮?
  • @rahulrai 我正在使用 cucumber 运行我的测试,所以它进入下一个测试步骤而没有给我任何错误。

标签: javascript java selenium selenium-webdriver pega


【解决方案1】:

我多次遇到类似的问题,我使用 -

修复它
while(driver.findElements(By.xpath("//button[contains(text(),'Submit')]")).size()!=0)
{
    driver.findElement(By.xpath("//button[contains(text(),'Submit')]")).click();
}

这只是一个临时修复,我只是在 Internet 上的某个地方找到的。我认为这是驱动程序本身的问题。

---- 编辑----

在单击按钮之前,您能否使用以下 javascript 命令确定页面是否已完全加载(Ajax)-

jQuery.active ==0 && document.readyState == "complete"

【讨论】:

    猜你喜欢
    • 2021-11-03
    • 2023-03-31
    • 2017-01-02
    • 1970-01-01
    • 2013-07-18
    • 1970-01-01
    • 2016-02-11
    • 2022-01-28
    • 2016-07-18
    相关资源
    最近更新 更多