Juliet Rybets Juliet Rybets - 3 months ago 16
Ajax Question

selenium get span text loaded with ajax

I have a price which loaded with Ajax and displayed in span. Certainly in Html is it hardcoded price 0. But on the page I see a new Price. And it's always the same problem: my Test doesn't see the price, which I get with Ajax request.

public void testSW40RolladenwelleKonfi() {
System.out.println("test preis SW40 Ausfuehrung Rolladenwelle Konfi");
driver.get("https://");
WebElement lange = driver.findElement(By.id("txt_sw_laenge"));
lange.clear();
lange.sendKeys("1000");
WebElement sw40 = driver.findElement(By.id("SW40"));
sw40.click();
WebDriverWait wait = new WebDriverWait(driver, 10);
Boolean element = wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//span[@id='productprice']/text()"), "10,00"));
assertTrue(element);
}


I had also tried:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
ExpectedConditions.presenceOfElementLocated(By.xpath("/span[@id='productprice']")));
assertEquals(element.getText(), "10,00");

Answer

Remove the /text() from your webdriver wait condition. Use below and check...

Boolean element =   wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//span[@id='productprice']"), "10,00"));
Comments