The user should not be able to type in the drop-down select list.
Language: Java
Framework: Selenium 4
1// Assumptions:2// 1. The website uses Selenium 4 Driver.3// 2. The dropdown select list is a <select> HTML tag.4// 3. The dropdown select list is identified by the "id" attribute.56// Import necessary libraries7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.support.ui.Select;1011public class TestScenario {12 13 public static void main(String[] args) {14 15 // Set the WebDriver to local driver16 WebDriver driver = new ChromeDriver();17 18 // Navigate to the webpage19 driver.get("http://www.example.com");20 21 // Find the dropdown select list element by ID22 WebElement dropdown = driver.findElement(By.id("selectList"));23 24 // Create a Select object using the dropdown element25 Select select = new Select(dropdown);26 27 // Enter text into the dropdown select list 28 select.sendKeys("Text");29 30 // Get the value of the dropdown select list 31 String value = select.getFirstSelectedOption().getText();32 33 // Check if the value of the dropdown select list is empty34 assert value.isEmpty() : "The user is able to type in the dropdown select list!";35 36 // Quit the browser37 driver.quit();38 39 // Uncomment the following code to connect to a remote client with desired capabilities40 /*41 DesiredCapabilities capabilities = new DesiredCapabilities();42 capabilities.setCapability("platformName", "android");43 capabilities.setCapability("deviceName", "Samsung Galaxy S7");44 45 WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);46 47 // Rest of the code48 */49 }50}
Language: Python
Framework: Selenium 4
1# Assumption: The select list is identified by the id "mySelect".2# Also, the test is being executed locally using ChromeDriver.34from selenium import webdriver5from selenium.webdriver.common.keys import Keys6from selenium.webdriver.support.ui import Select78# Local ChromeDriver initialization9driver = webdriver.Chrome()1011# Remote client with desired capabilities code12# desired_cap = {13# 'browserName': 'chrome',14# 'version': '91.0',15# 'platform': 'WINDOWS',16# }17# driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=desired_cap)1819# Navigate to the webpage20driver.get("http://example.com")2122# Select the dropdown 23select = Select(driver.find_element_by_id("mySelect"))2425# Send typing keys to the dropdown26select.select_by_visible_text("Option 1")2728# Assertion to check if the user is unable to type in the drop-down select list 29assert not driver.find_element_by_id("mySelect").get_attribute("typeable") 3031# Close the browser32driver.quit()
Language: Javascript
Framework: Cypress
1describe('General webpage functionality', () => {2 it('should restrict typing in drop-down select list', () => {3 //Assuming there is a drop-down select list with id 'select-list'4 cy.visit('http://example.com');5 cy.get('#select-list').should('be.visible').click();6 7 //Verify that typing is not allowed8 cy.get('#select-list').type('Option 1').should('have.value', '');910 //Assuming that there are no options already selected11 //Select the first option and verify that it is selected12 cy.get('#select-list').select('Option 1');13 cy.get('#select-list').should('have.value', 'Option 1');14 15 //Add commented code to connect to remote client with desired capabilities16 /*17 const remoteDriverUrl = 'http://localhost:4444/wd/hub';18 const desiredCapabilities = {19 browserName: 'chrome',20 'goog:chromeOptions': {21 'args': ['--headless']22 }23 };24 cy.customCommand('createSession', {25 remoteDriverUrl,26 desiredCapabilities27 }).then((sessionData) => {28 const { sessionId, browser } = sessionData;29 cy.log(`Created session with session id: ${sessionId}`)30 browser.url('http://example.com');31 //Add remaining test code here.32 browser.deleteSession();33 });34 */35 });36});
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