Show List

Performing actions on web page elements

In Selenium, you can perform various actions on web page elements such as clicking, typing, selecting, etc. using the Selenium WebDriver API. Here are some examples of how to perform common actions on web page elements using Selenium:

  • Clicking an element: You can click an element using the click() method of the WebElement class. For example, if you want to click a button with the ID "submitButton", you can write the following code:
python
Copy code
WebElement submitButton = driver.findElement(By.id("submitButton")); submitButton.click();
  • Typing text into an input field: You can type text into an input field using the sendKeys() method of the WebElement class. For example, if you want to type "hello" into an input field with the ID "inputField", you can write the following code:
python
Copy code
WebElement inputField = driver.findElement(By.id("inputField")); inputField.sendKeys("hello");
  • Selecting an option from a dropdown list: You can select an option from a dropdown list using the selectByValue(), selectByIndex(), or selectByVisibleText() method of the Select class. For example, if you want to select an option with the value "option1" from a dropdown list with the ID "dropdownList", you can write the following code:
vbnet
Copy code
WebElement dropdownList = driver.findElement(By.id("dropdownList")); Select dropdown = new Select(dropdownList); dropdown.selectByValue("option1");
  • Submitting a form: You can submit a form using the submit() method of the WebElement class. For example, if you want to submit a form with the ID "form", you can write the following code:
less
Copy code
WebElement form = driver.findElement(By.id("form")); form.submit();

These are just a few examples of the actions that you can perform on web page elements using Selenium. You can find more information and examples in the Selenium documentation.


    Leave a Comment


  • captcha text