handling checkboxes dynamically
driver.get("https://rahulshettyacademy.com/AutomationPractice/") checkboxes = driver.find_elements(By.XPATH,"//input[@type='checkbox']") for checkbox in checkboxes: if checkbox.get_attribute("value") == "option2": checkbox.click() assert checkbox.is_selected() break
for radiobuttons, let's try using class name.
radiobuttons = driver.find_elements(By.CSS_SELECTOR, ".radioButton") radiobuttons[2].click() assert radiobuttons[2].is_selected()
check if element is displayed/hidden
assert driver.find_element(By.ID,"displayed-text").is_displayed() driver.find_element(By.ID,"hide-textbox").click() assert not driver.find_element(By.ID,"displayed-text").is_displayed()
how to handle javascript alert popups.
driver.get("https://rahulshettyacademy.com/AutomationPractice/") name = "Rahul" driver.find_element(By.CSS_SELECTOR,"#name").send_keys(name) driver.find_element(By.ID,"alertbtn").click() alert = driver.switch_to.alert alertText = alert.text print(alertText) assert name in alertText alert.accept() # alert.dismiss() if ok,cancel there.
sample code: github folder
No comments:
Post a Comment