Есть такой скрипт , подскажите как правильно написать ожидание загрузки аякса , читаю-читаю , не могу все это собрать в кучу
Сейчас использую Thread.sleep(6000);
_________________________________________________________________________________________________
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class class2 {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testUntitledTestCase() throws Exception {
driver.findElement(By.name("add-to-cart")).click();
driver.findElement(By.linkText("Просмотр корзины")).click();
driver.findElement(By.linkText("Оформить заказ")).click();
driver.findElement(By.id("billing_first_name")).click();
driver.findElement(By.id("billing_first_name")).clear();
driver.findElement(By.id("billing_first_name")).sendKeys("test");
driver.findElement(By.id("billing_address_1")).click();
driver.findElement(By.id("billing_address_1")).clear();
driver.findElement(By.id("billing_address_1")).sendKeys("tset");
driver.findElement(By.id("billing_city")).click();
driver.findElement(By.id("billing_city")).clear();
driver.findElement(By.id("billing_city")).sendKeys("test");
driver.findElement(By.id("billing_phone")).click();
driver.findElement(By.id("billing_phone")).clear();
driver.findElement(By.id("billing_phone")).sendKeys("1111111111111111111111111");
driver.findElement(By.id("billing_email")).click();
driver.findElement(By.id("billing_email")).click();
// ERROR: Caught exception [ERROR: Unsupported command [doubleClick | id=billing_email | ]]
driver.findElement(By.id("billing_email")).clear();
driver.findElement(By.id("billing_email")).sendKeys("test@test.com");
Thread.sleep(6000);
driver.findElement(By.id("place_order")).click();
driver.findElement(By.cssSelector("p.woocommerce-notice.woocommerce-notice--success.woocommerce-thankyou-order-received")).click();
try {
assertEquals("Спасибо. Ваш заказ был принят.", driver.findElement(By.cssSelector("p.woocommerce-notice.woocommerce-notice--success.woocommerce-thankyou-order-received")).getText());
} catch (Error e) {
verificationErrors.append(e.toString());
}
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}