public async Task <string> SendKeysToElement(string elementId, string keys) { var isInput = await elementUtils.IsElementAttributeEqualToIgnoreCase(elementId, "tagName", "input"); var isFile = await elementUtils.IsElementAttributeEqualToIgnoreCase(elementId, "type", "file"); if (isInput && isFile) { bool multiple = await elementUtils.IsElementAttributeEqualToIgnoreCase(elementId, "multiple", "true"); return(webView.SetFileInputFiles(elementId, keys)); } else { var startTime = DateTime.Now; bool isDisplayed = false; bool isFocused = false; if (Session.implicitWait != default(TimeSpan)) { while (true) { isDisplayed = await elementUtils.IsElementDisplayed(elementId); if (isDisplayed) { break; } isFocused = await elementUtils.IsElementFocused(elementId); if (isFocused) { break; } if (Session.implicitWait == default(TimeSpan)) { break; } if (DateTime.Now - startTime >= Session.implicitWait) { return(null); } await Task.Delay(100); } } bool isEnabled = await elementUtils.IsElementEnabled(elementId); if (!isEnabled) { return(null); } if (!isFocused) { await FocusElement(elementId); } //var res = SendKeysOnWindow(keys, true); await webView.DispatchKeyEvents(keys); return("ok"); } }
public async Task <string> SendKeysToElement(string elementId, string keys, CancellationToken cancellationToken = default(CancellationToken)) { var isInput = await _elementUtils.IsElementAttributeEqualToIgnoreCase(elementId, "tagName", "input", cancellationToken).ConfigureAwait(false); var isFile = await _elementUtils.IsElementAttributeEqualToIgnoreCase(elementId, "type", "file", cancellationToken).ConfigureAwait(false); if (isInput && isFile) { bool multiple = await _elementUtils.IsElementAttributeEqualToIgnoreCase(elementId, "multiple", "true", cancellationToken).ConfigureAwait(false); return(_webView.SetFileInputFiles(elementId, keys)); } else { var startTime = DateTime.Now; bool isDisplayed = false; bool isFocused = false; if (Session.ImplicitWait != default(TimeSpan)) { while (true) { isDisplayed = await _elementUtils.IsElementDisplayed(elementId, cancellationToken).ConfigureAwait(false); if (isDisplayed) { break; } isFocused = await _elementUtils.IsElementFocused(elementId, cancellationToken).ConfigureAwait(false); if (isFocused) { break; } if (Session.ImplicitWait == default(TimeSpan)) { break; } if (DateTime.Now - startTime >= Session.ImplicitWait) { throw new WebBrowserException("Element is not displayed or focused", "invalid element state"); } await Task.Delay(100, cancellationToken).ConfigureAwait(false); } } bool isEnabled = await _elementUtils.IsElementEnabled(elementId, cancellationToken).ConfigureAwait(false); if (!isEnabled) { throw new WebBrowserException("Element is not enabled", "invalid element state"); } if (!isFocused) { await FocusElement(elementId, cancellationToken).ConfigureAwait(false); } await _webView.DispatchKeyEvents(keys, cancellationToken).ConfigureAwait(false); return("ok"); } }