Performing actions on the AUT*

You can set an element’s text using the sendKeys method as follows:


String name = "Charles";
driver.findElement(By.name("name")).sendKeys(name);
  

name = "Charles"
driver.find_element_by_name("name").send_keys(name)
  

string name = "Charles";
driver.FindElement(By.Name("name")).SendKeys(name);
  

name = "Charles"
driver.find_element(name: "name").send_keys(name)
  

const name = "Charles";
await driver.findElement(By.name('name')).sendKeys(name);
  

val name = "Charles"
driver.findElement(By.name("name")).sendKeys(name)
  

Some web applications use JavaScript libraries to add drag-and-drop functionality. The following is a basic example of dragging one element onto another element:


WebElement source = driver.findElement(By.id("source"));
WebElement target = driver.findElement(By.id("target"));
new Actions(driver).dragAndDrop(source, target).build().perform();
  

source = driver.find_element_by_id("source")
target = driver.find_element_by_id("target")
ActionChains(driver).drag_and_drop(source, target).perform()
  

IWebElement source = driver.FindElement(By.Id("source"));
IWebElement target = driver.FindElement(By.Id("target"));
new Actions(driver).DragAndDrop(source, target).Build().Perform();
  

source = driver.find_element(id: "source")
target = driver.find_element(id: "target")
driver.action.drag_and_drop(source, target).perform
  

const actions = driver.actions({bridge: true});
const source = await driver.findElement(By.id('source'));
const target = await driver.findElement(By.id('target'));
await actions.dragAndDrop(source, target).perform();
  

val source = driver.findElement(By.id("source"))
val target = driver.findElement(By.id("target"))
Actions(driver).dragAndDrop(source, target).build().perform()
  

Clicking on an element

You can click on an element using the click method:


driver.findElement(By.cssSelector("input[type='submit']")).click();
  

driver.find_element_by_css_selector("input[type='submit']").click()
  

driver.FindElement(By.CssSelector("input[type='submit']")).Click();
  

driver.find_element(css: "input[type='submit']").click
  

await driver.findElement(By.css("input[type='submit']")).click();
  

driver.findElement(By.cssSelector("input[type='submit']")).click()
  

*AUT: Application under test