0
```
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.

Ankit
  • 1

1 Answers1

0

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);
  })
})
Fody
  • 23,754
  • 3
  • 20
  • 37