MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / SendKeys

Method SendKeys

dotnet/src/webdriver/WebElement.cs:571–601  ·  view source on GitHub ↗

Simulates typing text into the element. The text to type into the element. The text to be typed may include special characters like arrow keys, backspaces, function keys, and so on. Valid special keys are defined in . Thrown when the target elem

(string text)

Source from the content-addressed store, hash-verified

569 /// <exception cref="InvalidElementStateException">Thrown when the target element is not enabled.</exception>
570 /// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
571 public virtual void SendKeys(string text)
572 {
573 if (text == null)
574 {
575 throw new ArgumentNullException(nameof(text), "text cannot be null");
576 }
577
578 var fileNames = text.Split('\n');
579 if (fileNames.All(this.driver.FileDetector.IsFile))
580 {
581 var uploadResults = new List<string>();
582 foreach (var fileName in fileNames)
583 {
584 uploadResults.Add(this.UploadFile(fileName));
585 }
586 text = string.Join("\n", uploadResults);
587 }
588
589 // N.B. The Java remote server expects a CharSequence as the value input to
590 // SendKeys. In JSON, these are serialized as an array of strings, with a
591 // single character to each element of the array. Thus, we must use ToCharArray()
592 // to get the same effect.
593 // TODO: Remove either "keysToSend" or "value" property, whichever is not the
594 // appropriate one for spec compliance.
595 Dictionary<string, object> parameters = new Dictionary<string, object>();
596 parameters.Add("id", this.Id);
597 parameters.Add("text", text);
598 parameters.Add("value", text.ToCharArray());
599
600 this.Execute(DriverCommand.SendKeysToElement, parameters);
601 }
602
603 /// <summary>
604 /// Submits this element to the web server.

Callers

nothing calls this directly

Calls 4

UploadFileMethod · 0.95
ExecuteMethod · 0.95
SplitMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected