Clearing the content of a web element: (note - when simulating user actions in tests, it's better to send backspace, see next action)
interactionWebElement.clear();
Entering data - simulating sending keystrokes:
interactionWebElement.sendKeys("Text");
interactionWebElement.sendKeys(Keys.CONTROL + "c"); // copy to clipboard.
Getting the value of an element's attribute:
interactionWebElement.getAttribute("value");
interactionWebElement.getAttribute("style");
Getting element's text:
String elementsText = interactionWebElement.getText();
Selecting from dropdown:
Select dropDown = new Select(webElement);
dropDown.selectByValue(value);
Self explanatory:
interactionWebElement.click();
interactionWebElement.submit(); //for forms
interactionWebElement.isDisplayed();
interactionWebElement.isEnabled(); // for exampale - is clickable.
interactionWebElement.isSelected(); // for radio buttons.
Actions using org.openqa.selenium.interactions.Actions
:
Drag & Drop:
Action dragAndDrop = builder.clickAndHold(someElement)
.moveToElement(otherElement)
.release(otherElement)
.build();
dragAndDrop.perform();
Select multiple:
Action selectMultiple = builder.keyDown(Keys.CONTROL)
.click(someElement)
.click(someOtherElement)
.keyUp(Keys.CONTROL);
dragAndDrop.perform();
Self explanatory (using builder):
builder.doubleClick(webElement).perform();
builder.moveToElement(webElement).perform(); //hovering
See here for more examples of advanced actions and a complete list.
Using Javascript:
// Scroll to view element:
((JavascriptExecutor) driver).executeJavaScript("arguments[0].scrollIntoView(true);", webElement);