Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
Get the value of a rect attribute(fill color) in Testcafe with typescript

I've the following code:

<colored-item label="Label A" symbol-size-left="9.5" symbol-size-right="12" symbol-right="" symbol-left="<svg viewport="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
  <rect x="0" y="0" width="24" height="24" stroke="black" fill="rgb(0, 91, 142)" stroke-width="0" />
  </svg>" small-font="true"></colored-item>

and I need the value of the "fill" attribute("rgb(1, 89, 138)").

I tried the following:

const fillColor = await Selector('colored-item').getAttribute('symbol-left');

The result is:

<svg viewport="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
  <rect x="0" y="0" width="24" height="24" stroke="black" fill="rgb(1, 89, 138)" stroke-width="0" />
  </svg>

When I try

const fillColor = await Selector('colored-item').withAttribute('symbol-left').getAttribute('fill');

the result is "null"

Any ideas how to access the "fill" attribute directly?

Otherwise I need to use regex, right?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As far as I understand, you put the SVG element in the attribute of the colored-item. But to display this SVG on the page, it should be added to the DOM. Testcafe tries to search elements by DOM, so it means you should research DOM elements on the page and find out which selector you need to use exactly. According to the information that I see, you can get these attributes directly from rect: await Selector('rect').getAttribute('fill')

about 4 years ago · Juan Pablo Isaza Denunciar

0

I finally solved it via regex:

const fillColor = await (Selector('colored-item').getAttribute('symbol-left')).match(/fill="?([\d\w\(\ \,\)]*)"/)[1];

If you want to use it just substitute fill=" with your string expected to exclude and at the end the

" 
here 
)"/

with your expected end character (or string if needed)

The result will be a match and a group. Just select the group by adding [1] as seen above.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda