Search code examples
ajaxjsontextxpathclassname

Finding xpath for an element loaded by Ajax-json response using class and text


I have an element like

<td class="google-visualization-table-th gradient google-visualization-table-sorthdr">
Project Name
<span class="google-visualization-table-sortind">▼</span>
</td>

I tried

 driver.findElement(By.xpath("//td[contains(@class, 'google-visualization-table-th') and normalize-space(text()) = 'Project Name']")

But its not working. Basically its code for Column header and I need to recognize each column header and print if the heading exist or not.


Solution

  • Its resolved now, element was not getting identified because they were getting loaded in an iframe. I used the below code o switch to iframe and then did usual operations to track the elements.

    WebDriverWait wait = new WebDriverWait(driver, 200);
    By by = By.id("iframe id");
    try {
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(by));
    

    Thanks everyone for the help.