Appi
Appi

Reputation: 95

How do i fetch the text from a <svg> tag which contains the tag text

I wanted to fetch text from the g tag and wanted to disply on concsol. Total 21 rows and when i am clicking on it its give me popup(its not java or window based popup) I wanted to fetch some of the values from that pop and wanted to display on console.

After clicking on popup, contains 3 rows. Each row contains 3 td tag. The value of the first td tag displayed but finding difficulty to fetch the value of second td tag.

Here is Code:

<td style=" "        > Manager</td>
<td style="padding-right">
    <svg  width="100%" hight="50%"  id=" ">
        <g>
            <defs....>...</defs>
            <rect....>...</rect>
            <text x="10"  y="24" fill=" " syle=" ">30%</text>
                 </g>
         <g>
            <text x="10"  y="24" fill=" "  syle=" ">70%</text>
            <text x="10"  y="24" fill=" " syle=" ">80%</text>

         </g>
    </svg>
<td>

It has displayed 'Manager' on console but finding difficulty to print the text "30%", 70% and 80% on console.

This is the path which showing one element.

//div[@id='performanceMeasureDetailsModel']//div[2]//table[1]//tbody[1]//tr[1]//td[2]//* [name()='svg']//*[name()='g'][1]//*[text()='50%']

giving required element but text can be vary so what woulds be dynamic path for it. Same way wanted to print value of second g tag, and for all 21 rows.

If anybody knows how to fetch text tag contains text? Will be a great help. Thanks.

Upvotes: 1

Views: 450

Answers (1)

KunduK
KunduK

Reputation: 33384

Try this below xpath.This should identify all 21 elements.

//*[name()='svg']//*[name()='text']

To get all elements text

WebDriverWait wait = new WebDriverWait(driver, 20);         
List<WebElement> Items=wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[name()='svg']//*[name()='text']")));
        for(int i=0;i<Items.size();i++)
        {
            System.out.println(Items.get(i).getText());

        }

Upvotes: 1

Related Questions