Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
How to find elements based on computed style

I wanted to find all element having specific font color in my selenium automation project. but as the font color style is not inline it will not be visible in DOM. Is there anyway to find elements based on their computed style? may be using xpath or css or finding such elements using JavaScript?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

try this,

const color = 'rgb(255, 0, 0)' // use rgb color codes.
const elements = Array.from(document.body.getElementsByTagName("*"));
const specificFontColoredElements = elements.filter(elm => {
  const style = getComputedStyle(elm)
  return style?.color === color
})
console.log(specificFontColoredElements)
h2 {
  color: red;
}

.greencolor {
  color: green
}
<h2>I'm red</h2>
<p>I do not have user styled color!</p>
<h2 class="greencolor">I'm green</h2>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!