Selenium 3.0 Keyboard Event + Force end Chromedriver Process Code

Source: Internet
Author: User

Selenium automated testing often uses keyboard operations, which are the detailed operation of the keyboard, and part of the code. From the worm division of Automation-related books.

public static void Main (string[] args) throws Interruptedexception {
System.setproperty ("Webdriver.chrome.driver", "D:/chromedriver_win32/chromedriver.exe");
Chromeoptions Options = new Chromeoptions ();
Options.addarguments ("User-data-dir=c:\\users\\happy\\appdata\\local\\google\\chrome\\user data");
Webdriver Driver = new Chromedriver (Options);
try {

Driver.get ("https://www.baidu.com");
Webelement target = driver.findelement (by.id ("kw"));
Target.sendkeys ("I am an automated script");
Enter information in the Baidu text box
Thread.Sleep (3000);
Target.sendkeys (Keys.back_space);
Delete a character after
Thread.Sleep (3000);
Target.clear ();
Clear the contents of the text box

Thread.Sleep (3000);
Target.sendkeys (Keys.space);
Enter a space
Thread.Sleep (3000);
Target.sendkeys ("I am an automated script");
Re-enter
Thread.Sleep (3000);
Target.sendkeys (Keys.control, "a");
Select All
Thread.Sleep (3000);
Target.sendkeys (Keys.control, "X");
Shear
Thread.Sleep (3000);
Target.sendkeys (Keys.control, "V");
Paste
Thread.Sleep (3000);
Target.sendkeys (Keys.enter);
Click Enter. Typically used for login scenarios
Thread.Sleep (5000);

} finally {

try {
Driver.close ();
Runtime.getruntime (). EXEC ("taskkill/f/im" + "Chromedriver.exe");
Runtime.getruntime (). EXEC ("taskkill/f/im" + "Chrome.exe");
End the process. The above is used to end the Chromedriver process when an exception occurs and to avoid chromedriver consuming memory resources. Close (), and the Quit () method sometimes fail to end the chromedriver process.
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}

}

Selenium 3.0 Keyboard Event + Force end Chromedriver Process Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.