Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
829 views
in Technique[技术] by (71.8m points)

c# - Issue With CefSharp Browser SendKeys

I am using chromium browser to automate some task.

Basically I want to load images for that I have to click "Add Image" anchor tag on the webpage.

So I cannot directly click it not sure why when other works with same code. But I have managed to bring the focus on that anchor tag but sending :

 KeyEvent k = new KeyEvent();
 k.WindowsKeyCode = 9;  // TAB KEY
 browser.GetBrowser().GetHost().SendKeyEvent(k); 
 //browser = ChromiumWebBrowser browser;

The above work perfectly fine as i see it coming to the correct anchor Tag.

Now i do :

 KeyEvent k = new KeyEvent();
 k.WindowsKeyCode = 13;   //ENTER KEY
 browser.GetBrowser().GetHost().SendKeyEvent(k);

To simulate enter key , however nothing happens but if I press "Enter" manually on Keyword it works fine so why the above is not acting same as me clicking "Enter Key"

Any suggestions.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I used your code like this, and it works for me.

KeyEvent k = new KeyEvent();
k.WindowsKeyCode = 0x0D;
k.FocusOnEditableField = true;
k.IsSystemKey = false;
k.Type = KeyEventType.Char;
Browser.GetBrowser().GetHost().SendKeyEvent(k);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...