'In the cypress automation, want to retrive the the text of the pie chart?
```
String veritcalXpath = "//*[local-name()='svg']//*[name()='g' and @class = 'highcharts-series-group']//*[name()='rect']";
String textXpath = "//*[local-name()='svg']//*[name()='g' and @class = 'highcharts-label highcharts-tooltip highcharts-color-undefined']//*[name()='text']";
List<WebElement> barList = driver.findElements(By.xpath(veritcalXpath));
System.out.println("Total bar list size is:- " + barList.size());
Actions act = new Actions(driver);
for (WebElement e : barList) {
act.moveToElement(e).perform();
// Thread.sleep(500);
String text = driver.findElement(By.xpath(textXpath)).getText();
System.out.println(text);
This code is for your understanding, I want to implement this in the cypress Automation. Please let me know how can implement this in the cypress for automating the Pie Chart.
Solution 1:[1]
It's pretty much the same code, with Cypress command flavour. Some nesting is required because the commands retry and are therefore asynchronous.
But you should add the package cypress-xpath.
You may have to adjust this a bit as I don't know your application.
const veritcalXpath = "//*[local-name()='svg']//*[name()='g' and @class = 'highcharts-series-group']//*[name()='rect']";
const textXpath = "//*[local-name()='svg']//*[name()='g' and @class = 'highcharts-label highcharts-tooltip highcharts-color-undefined']//*[name()='text']";
cy.xpath(veritcalXpath)
.then($els => {
cy.log(`Total bar list size is:- ${$els.length}`)
})
.each(($el, index) => {
cy.xpath(textXpath).eq(index).then($el => {
const text = $el.text();
cy.log((text);
})
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fody |
