getCSSProperty
Obtiene una propiedad CSS de un elemento DOM seleccionado mediante el selector dado. El valor devuelto está formateado para ser comprobable. Los colores se analizan mediante rgb2hex y todas las demás propiedades se analizan mediante css-value.
información
Ten en cuenta que las propiedades CSS abreviadas (por ejemplo, background
, font
, border
, margin
,
padding
, list-style
, outline
, pause
, cue
) se expandirán para obtener todas las propiedades
completas, lo que resultará en múltiples llamadas a WebDriver. Si estás interesado en una propiedad
específica, se recomienda consultar directamente por ella.
Uso
$(selector).getCSSProperty(cssProperty, pseudoElement)
Parámetros
Nombre | Tipo | Detalles |
---|---|---|
cssProperty | string | nombre de la propiedad CSS |
pseudoElement | PseudoElement | pseudo elemento CSS |
Ejemplos
example.html
<label id="myLabel" for="input" style="color: #0088cc; font-family: helvetica, arial, freesans, clean, sans-serif, width: 100px">Some Label</label>
getCSSProperty.js
it('should demonstrate the getCSSProperty command', async () => {
const elem = await $('#myLabel')
const color = await elem.getCSSProperty('color')
console.log(color)
// outputs the following:
// {
// property: 'color',
// value: 'rgba(0, 136, 204, 1)',
// parsed: {
// hex: '#0088cc',
// alpha: 1,
// type: 'color',
// rgba: 'rgba(0, 136, 204, 1)'
// }
// }
const font = await elem.getCSSProperty('font-family')
console.log(font)
// outputs the following:
// {
// property: 'font-family',
// value: 'helvetica',
// parsed: {
// value: [ 'helvetica', 'arial', 'freesans', 'clean', 'sans-serif' ],
// type: 'font',
// string: 'helvetica, arial, freesans, clean, sans-serif'
// }
// }
var width = await elem.getCSSProperty('width', '::before')
console.log(width)
// outputs the following:
// {
// property: 'width',
// value: '100px',
// parsed: {
// type: 'number',
// string: '100px',
// unit: 'px',
// value: 100
// }
// }
})
Retorna
- <CSSProperty>
return
: La propiedad CSS especificada del elemento