change attribute value using selenuim python



  • I am try to change non input attribute value in Firefox frame in the format:

     <div id='100' class='abc'>
    <p> hello </p>
    </div>
    <div id='200' class='abc'>
    <p> hello 2 </p>
    </div>
    …..
    

    I want to change hello 2 to welcome I try this code but it does not work

    driver.execute_script("document.getElementsByClassName('abc')[0].text='welcome';");
    


  • Your locator would fetch the first div, of id = 100.

    Try the following:

    document.querySelector('#200 p').innerText='welcome';
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2