Java Selenium在单击按钮后等待AJAX请求完成

Java Selenium在单击按钮后等待AJAX请求完成,java,ajax,selenium,selenium-webdriver,Java,Ajax,Selenium,Selenium Webdriver,当我填写完表单并单击submit按钮时,我正在尝试等待呼叫返回,然后检查插入的数据是否显示在我的视图中 我正在想办法让它工作。查看页面标记时,它将刷新视图。有没有一种方法可以让我这样做:等到WebElement的子元素发生变化 我在想,在搜索插入的数据之前,我可以坐在视图的父视图旁,监视子视图的变化 我不确定WebDriverWait是否通过在父WebElement上设置某种侦听器来完成该任务 以下是我一直在使用的一些代码: public WebElement getWebElement(Str

当我填写完表单并单击submit按钮时,我正在尝试等待呼叫返回,然后检查插入的数据是否显示在我的视图中

我正在想办法让它工作。查看页面标记时,它将刷新视图。有没有一种方法可以让我这样做:等到WebElement的子元素发生变化

我在想,在搜索插入的数据之前,我可以坐在视图的父视图旁,监视子视图的变化

我不确定
WebDriverWait
是否通过在父
WebElement
上设置某种侦听器来完成该任务

以下是我一直在使用的一些代码:

public WebElement getWebElement(String selector){
  return (new WebDriverWait(driver,5000))
    .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(selector)));
}

public submitButton(){
  WebElement submit = getWebElement("#mybutton");
  WebElement gridDataParent = getWebElement("#myTable > tbody");

  //Not quite sure how to check for child changes, and start a listener here

  submit.click();

}
我想一定有某种方法可以监控给定根目录下的更改,不是吗


按钮提交后,它将执行服务器调用,调用后将刷新数据集。

尝试使用此按钮,直到您正在查看的元素出现在DOM中

waitForElementPresent(locator)

据我所知,您可能正在等待表数据的更新。如果是这样,则在提交任何数据之前,首先计算行数。再次检查表数据是否增加

       int numberCountBeforeTableLoad = driver.findElements(By.cssSelector("your table rows locator")).size();//count row number of your desired table before submitting data
       //here submit your data and wait until your table loads with a row count more than previous row count
       WebDriverWait wait = new WebDriverWait(driver, 20);
       wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("your table rows locator"), numberCountBeforeTableLoad));

因为数据集涉及分页,所以它出现在当前页面上的可能性未知,但是给定页面上的数据确实刷新了,我喜欢这个答案。