![](/img/trans.png)
[英]OpenQA.Selenium.WebDriverException : unknown error: a.tagName.toUpperCase is not a function with reactJS elements through Selenium and C#
[英]OpenQA.Selenium.WebDriverException: 'unknown error: ChromeDriver only supports characters in the BMP while sending an emoji through C# Selenium
我正在嘗試發送一個表情符號。我嘗試通過處理信號 👍 來發送它,但它引發了這個異常。
OpenQA.Selenium.WebDriverException: 'unknown error: ChromeDriver only supports characters in the BMP
比我嘗試將其作為 unicode 發送,但沒有任何成功。 它不是理想的標志。
input.SendKeys("/u1F44D")
發送表情符號的正確方法是什么?
OpenQA.Selenium.WebDriverException: 'unknown error: ChromeDriver only supports characters in the BMP
Javascript代碼中的解決方案
async sendKeysWithEmojis(element, text) {
const script = `var elm = arguments[0],
txt = arguments[1];elm.value += txt;
elm.dispatchEvent(new Event('keydown', {bubbles: true}));
elm.dispatchEvent(new Event('keypress', {bubbles: true}));
elm.dispatchEvent(new Event('input', {bubbles: true}));
elm.dispatchEvent(new Event('keyup', {bubbles: true}));`;
await this.driver.executeScript(script, element, text);
}
像這樣稱呼它
const element = await this.driver.findElement(selector);
await sendKeysWithEmojis(element, '🚀😀 This one shall pass 🚀😀');
這里發生了什么? 我們正在使用事件模擬本機按鍵
請注意{bubbles: true}
是可選的(在我的情況下由於復雜的包裝輸入而需要)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.