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 theWebElement
class. For example, if you want to click a button with the ID "submitButton", you can write the following code:
pythonCopy 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 theWebElement
class. For example, if you want to type "hello" into an input field with the ID "inputField", you can write the following code:
pythonCopy 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()
, orselectByVisibleText()
method of theSelect
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:
vbnetCopy 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 theWebElement
class. For example, if you want to submit a form with the ID "form", you can write the following code:
lessCopy 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