'Python Selenium: how to change "disabled" attribute to "enabled" [duplicate]
I use this code:
commit = driver.find_element(by=By.XPATH, value="/html/body/div[2]/div/div/div/form/div[1]/div[4]/button")
driver.execute_script("arguments[0].setAttribute('enabled', true)", commit)
But the attribute does not change.
I guess I'm using the .execute_script() function incorrectly.
I can change this attribute manually and it will give the result I want. Shown in screenshots:

How can i change this attribute with Selenium?
P.S. XPATH is correct.
Solution 1:[1]
There are few things to notice.
driver.find_element(by=By.XPATHshould bedriver.find_element(By.XPATH, "XPath here")Do not use absolute xpath, instead use relative path.
//button[@type='submit' and contains(@class,'gtm_reg_btn') and @disabled]
You will have to make sure that, it in unique in HTMLDOM.
Steps to check:
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.
Bit of change you will have to make here:
Instead of this:
driver.execute_script("arguments[0].setAttribute('enabled', true)", commit)
Use this:
driver.execute_script("arguments[0].setAttribute('disabled','enabled')", commit)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | cruisepandey |
