echarts Unable to click on label when label text matches title text

nqwrtyyt  于 2023-02-04  发布在  Echarts
关注(0)|答案(3)|浏览(237)

Version

5.3.0

https://codepen.io/nani554/pen/WNdRBzR

Steps to Reproduce

  1. Create any chart, lets say bar chart and render it in SVG.
  2. Have Title whose text(Mon) is similar to one of the labels text(Mon).

please refer codepen for chart example:
https://codepen.io/nani554/pen/WNdRBzR

Current Behavior

  1. What i need is to click on label text, so i have formed a selector using text value and want to click on label text programatically but its not happening because in dom we have multiple text elements with same text value, which are "Label text" and "Title text".
  2. Currently there is no way to form a unique selector as every text is present in text element and its parent in "g" element with its parent as "svg" element.
  3. This is the selector im using:
    selector: "body svg text:contains('Mon')";
  4. Im using cypress to query selector and do click event.

please refer below images for reference.

UI:

DOM:

Soo Currently Im not able to click on label text with that selector.

Expected Behavior

Please suggest me a way for me to form a unique selector for label text or title text or legends.
let me know if i can add id or class attributes to text element, so that i can uniqely select that element and do operations on it.

Thank you.

Environment

- OS: Windows 7 - 10.
- Browser: Chrome 99.0.4844.82 (Official Build) (64-bit)
- Framework: Angular@11.2.14

Any additional comments?

No response

rekjcdws

rekjcdws1#

If you hope to listen to the events of axis labels, it's suggested to use chart.on API instead of attempting to fetch the generated element. Refer to #16500 (comment) for more information.

a2mppw5e

a2mppw5e2#

My case is not about listening to event but clicking on specific element in cypress environment (automation).
Example: cy.get('.btn').click()
https://docs.cypress.io/api/commands/click#Syntax
So here whats happening is, im clicking on a element which has class "btn". So similarly i need a unique selector to click on axis label.

y3bcpkx1

y3bcpkx13#

Actually If I understand the question correctly we need an ability to uniquely identify and target a specific DOM element in the so that we can click on the exact element based on the unique selector we can form.

Currently I don't see a way if we can assign some id's or css classes to the svg elements so that they can be leveraged to target a specific DOM element using dom selectors.

It would be a very useful thing especially from the automation standpoint.

相关问题