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

515
Views
How to change the value of the class attribute of an element using Python and Selenium

I want to change the class name, but it doesn't work for me.

<div class="vcp-controls-panel vcp-playing hide">

FullXpath:

/html/body/div[1]/div/div/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[1]/div[3]/div/div[1]/div/div[1]/div[9]/div[4]

I want to change vcp-playing hide to vcp-playing show but it doesn't work

selects = driver.find_element_by_class_name("vcp-playing hide")
    for select in selects:
        driver.execute_script("arguments[0].setAttribute('class', 'vcp-playing show')", select)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As the existing element already have the classname attribute set:

<div class="vcp-controls-panel vcp-playing hide">

You can remove the existing attributes through removeAttribute() set the new attributes using setAttribute() as follows:

selects = driver.find_elements(By.CSS_SELECTOR, "div.vcp-controls-panel.vcp-playing.hide")
for select in selects:
    driver.execute_script("arguments[0].removeAttribute('class')", select);
    driver.execute_script("arguments[0].setAttribute('class','vcp-controls-panel vcp-playing show')", select)

Note : You have to add the following imports :

from selenium.webdriver.common.by import By
about 4 years ago · Juan Pablo Isaza Report

0

how about do it completely in javascript

driver.execute_script("""
    selects = document.querySelectorAll('.vcp-playing.hide')
    selects.forEach(e => e.setAttribute('class', 'vcp-playing show'))
""")
about 4 years ago · Juan Pablo Isaza 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!