General webpage functionality : Verify autosave in check box

Verify the autosave is working as expected while we using check box

Language: Java

Framework: Selenium 4

copy
1/​/​Assuming that the webpage is a form where user can select multiple checkboxes2/​/​Assuming that the autosave functionality is working as expected for other elements in the form34import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.chrome.ChromeOptions;910public class CheckboxAutosaveTest {1112 public static void main(String[] args) {13 14 /​/​To use local driver15 System.setProperty("webdriver.chrome.driver", "path/​to/​chromedriver");16 17 /​/​To connect to remote client with desired capabilities18 /​/​ChromeOptions chromeOptions = new ChromeOptions();19 /​/​chromeOptions.setCapability("browserName", "chrome");20 /​/​WebDriver driver = new RemoteWebDriver(new URL("remoteDriverURL"), chromeOptions);21 22 WebDriver driver = new ChromeDriver();23 driver.get("urlOfWebpage");24 25 /​/​Assuming that multiple checkboxes with different ids are available26 WebElement checkbox = driver.findElement(By.id("checkbox1"));27 checkbox.click();28 29 /​/​Assuming that autosave functionality will trigger after every checkbox click30 driver.navigate().refresh();31 32 if(checkbox.isSelected()) {33 System.out.println("Autosave functionality is working as expected");34 } else {35 System.out.println("Autosave functionality is not working as expected");36 }37 38 driver.quit();39 }4041}

Language: Python

Framework: Selenium 4

copy
1from selenium import webdriver2from selenium.webdriver.common.keys import Keys3from selenium.webdriver.chrome.options import Options45#Assumptions: We are testing on a web application with a single page with checkboxes and 6#an autosave feature that saves the checkbox state even after page refresh.7#We will use ChromeDriver in this example.89#Locally 10driver = webdriver.Chrome()11#Remotely 12#chrome_options = Options()13#chrome_options.add_argument('--no-sandbox')14#chrome_options.add_argument('--disable-dev-shm-usage')15#driver = webdriver.Remote(command_executor='http:/​/​remoteclientaddress:port/​wd/​hub', desired_capabilities=chrome_options.to_capabilities())1617#Open the webpage18driver.get("https:/​/​example.com")1920#Find the checkbox element21checkbox = driver.find_elements_by_xpath("/​/​input[@type='checkbox']")2223#Click on the checkbox24checkbox.click()2526#Refresh the page27driver.refresh()2829#Verify that the checkbox is still checked30assert checkbox.is_selected()3132#Close the browser33driver.quit()

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing