Verify the field of pin code, pincode field on an ecommerce website should be editable
Language: Java
Framework: Selenium 4
1// Assumptions2// - The website under test has a registration or checkout page with a pin code field3// - The pin code field is identified by a unique ID or name45// Import required Selenium libraries6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.By;9import org.openqa.selenium.chrome.ChromeDriver;1011public class PinCodeFieldTest {12 13 public static void main(String[] args) {14 15 // Set path to the chrome driver16 System.setProperty("webdriver.chrome.driver", "path/to/chrome/driver");17 18 // Create instance of the Chrome driver19 WebDriver driver = new ChromeDriver();20 21 // Navigate to the ecommerce website22 driver.get("https://www.ecommercewebsite.com/checkout");23 24 // Find the pin code field by its ID or name and store it in a WebElement variable25 WebElement pinCodeField = driver.findElement(By.id("pin-code-field"));26 27 // Verify that the pin code field is editable28 if (pinCodeField.isEnabled()) {29 System.out.println("PASS: Pin code field is editable");30 } else {31 System.out.println("FAIL: Pin code field is not editable");32 }33 34 // Close the browser window35 driver.quit();36 37 // Code to connect to remote client with desired capabilities (Assuming remote client is running Selenium Grid 4)38 // DesiredCapabilities capabilities = new DesiredCapabilities();39 // capabilities.setBrowserName("chrome");40 // WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);41 }42 43}
Language: Python
Framework: Selenium 4
1# Assuming the webpage has already been loaded and the pincode field is present23# Importing packages4from selenium import webdriver5from selenium.webdriver.common.keys import Keys6from selenium.webdriver.common.desired_capabilities import DesiredCapabilities78# Creating a local webdriver instance9driver = webdriver.Chrome()1011# Additional code to connect to a remote client with desired capabilities12'''13options = webdriver.ChromeOptions()14options.add_argument('headless')15desired_capabilities = DesiredCapabilities.CHROME16desired_capabilities['loggingPrefs'] = {'browser': 'ALL'}17driver = webdriver.Remote(18 command_executor='http://localhost:4444/wd/hub',19 desired_capabilities=options.to_capabilities().merge(desired_capabilities)20)21'''2223# Locating the pincode field and verifying it is editable24pincode_field = driver.find_element_by_id('pincode')25pincode_field.clear()26pincode_field.send_keys('123456')27assert pincode_field.get_attribute('value') == '123456'2829# Quitting the webdriver instance30driver.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.
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.
Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.
Start Free Testing