问题
Im trying to write an email-address into an input field using Selenium and ChromeDriver in C#. Nothing spectacular so far. But in case of strings, containing "@"characters it is sending the content of the clipboard instead of this character.
For example: The Content of the Clipboard ist "####MYCLIPBOARDCONTENT######" Copied by Ctrl+C
Execution of the Lines
var input = _webDriver.FindElement(By.Id(id));
input.Clear();
input.SendKeys("abc@def.test");
Is leading to this in the UI
Can anyone confirm this behaviour? How to deal with it? I don't want to bypass this by some strange hacks.
回答1:
Use action chains to build "AltGr + Q".
var actions = new OpenQA.Selenium.Interactions.Actions(driver);
actions.KeyDown(Keys.Control).KeyDown(Keys.Alt); //press Alt
actions.SendKeys("Q"); //press Q
actions.KeyUp(Keys.Control).KeyUp(Keys.Alt); //Release key
actions.Build().Perform();
回答2:
Actually i don't want to use these hacks for such basic string operations.
But i found the issue by myself now. It was related to my language settings in Windows. I was using 1. EN-US, 2. DE-DE, and 3. EN-HR. I removed the third one. Now it is working as expected.
来源:https://stackoverflow.com/questions/64385485/selenium-sendkeys-with-chromedriver-uses-clipboard-content-instead-of-char