Juliet Rybets Juliet Rybets - 1 year ago 92
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");
WebElement lange = driver.findElement(By.id("txt_sw_laenge"));
WebElement sw40 = driver.findElement(By.id("SW40"));
WebDriverWait wait = new WebDriverWait(driver, 10);
Boolean element = wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//span[@id='productprice']/text()"), "10,00"));

I had also tried:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
assertEquals(element.getText(), "10,00");

Answer Source

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"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download