Test Overview
This test opens a web page, finds a button element, modifies its 'disabled' attribute using JavaScript, and verifies that the button is enabled afterwards.
This test opens a web page, finds a button element, modifies its 'disabled' attribute using JavaScript, and verifies that the button is enabled afterwards.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class TestModifyAttribute(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/testpage') def test_enable_button_with_js(self): driver = self.driver wait = WebDriverWait(driver, 10) # Wait until button is present button = wait.until(EC.presence_of_element_located((By.ID, 'submit-btn'))) # Initially button is disabled self.assertTrue(button.get_attribute('disabled') is not None) # Use JS to remove 'disabled' attribute driver.execute_script("arguments[0].removeAttribute('disabled')", button) # Verify button is enabled self.assertIsNone(button.get_attribute('disabled')) def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to load the test page | - | PASS |
| 2 | Navigates to 'https://example.com/testpage' | Page loads with a button element having id 'submit-btn' and attribute 'disabled' | - | PASS |
| 3 | Waits until the button with id 'submit-btn' is present | Button element is found in the DOM | Button element is located successfully | PASS |
| 4 | Checks that the button has 'disabled' attribute initially | Button is disabled on the page | Assert button.get_attribute('disabled') is not None | PASS |
| 5 | Executes JavaScript to remove 'disabled' attribute from the button | Button attribute 'disabled' is removed, button becomes enabled | - | PASS |
| 6 | Checks that the button no longer has 'disabled' attribute | Button is enabled and clickable | Assert button.get_attribute('disabled') is None | PASS |
| 7 | Test ends and browser closes | Browser window is closed | - | PASS |