मुख्य सामग्री पर जाएं

सीएसएस प्रॉपर्टी प्राप्त करें

दिए गए सेलेक्टर द्वारा चुने गए DOM-एलिमेंट से CSS प्रॉपर्टी प्राप्त करें। रिटर्न वैल्यू परीक्षण योग्य होने के लिए फॉर्मेट किया गया है। रंगों को rgb2hex के माध्यम से पार्स किया जाता है और अन्य सभी प्रॉपर्टीज css-value के माध्यम से पार्स की जाती हैं।

जानकारी

ध्यान दें कि शॉर्टहैंड CSS प्रॉपर्टीज (जैसे background, font, border, margin, padding, list-style, outline, pause, cue) को विस्तारित किया जाएगा जिससे सभी लॉन्गहैंड प्रॉपर्टीज प्राप्त करने के लिए कई WebDriver कॉल्स होंगी। यदि आप किसी विशिष्ट लॉन्गहैंड प्रॉपर्टी में रुचि रखते हैं, तो उसके लिए क्वेरी करना अनुशंसित है।

उपयोग
$(selector).getCSSProperty(cssProperty, pseudoElement)
पैरामीटर्स
नामटाइपविवरण
cssPropertystringcss प्रॉपर्टी का नाम
pseudoElementPseudoElementcss स्यूडो एलिमेंट
उदाहरण
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
// }
// }
})
रिटर्न्स
  • <CSSProperty> return: एलिमेंट की निर्दिष्ट CSS

Welcome! How can I help?

WebdriverIO AI Copilot