✔ How To Automate Pressing Keyboard Keys Using Selenium & Robot Class | (Video 67)

Опубликовано: 20 Сентябрь 2019
на канале: Rex Jones II
3,829
21

How To Automate Pressing Keyboard Keys Using Selenium & Robot Class

Some applications require the use of a key from a keyboard to complete a function. Pressing keys can be carried out utilizing Selenium’s sendKeys method and the Robot Class. This video presses an Enter Key from the https://api.jquery.com/ application because the search icon does not work.

► Download Transcript and Code https://www.rexjones2.com/automate-pr...

► Free Selenium PDF Book: https://www.rexjones2.com/book-seleni...
► Free Java PDF Book: https://www.rexjones2.com/book-part-1...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books

► Connect With Me via LinkedIn   / rexjones34  
► Subscribe To This Channel https://www.youtube.com/c/RexJonesII?...

► Transcript
Hello and Welcome. In this video, we are going to automate pressing keys on the keyboard. This jQuery application allows us to search but does not allow us to click the Search icon. Notice, how I typed api but nothing happens after clicking the icon. However, this other jQuery application is different. We can search for api, click the Search icon, and we see Results. In order to continue with our search on the first   / application  , we must press the Enter key then we see some results.

Let’s automate pressing the Enter key by inspecting the WebElement. The id attribute is not available so we are going to use the name attribute which has a value of s.
Let’s go to Eclipse. We will use the Selenium’s Keys class and the Robot class to press the Enter Key. Find the element by writing driver.findElement(By.name("s")).sendKeys("Test"); On the next line, we will press the Enter key. driver.findElement(By.name("s")).sendKeys The Enter key is pressed using the sendKeys method. Now, we write Keys dot and there are a lot of methods: Arrow Down, Left, Right, Up, Backspace, Cancel but we want Enter. That’s how we automate using the Selenium class.

Now, let’s automate using the Robot class. Start with the Robot class robot = new Robot (); Import the class. The Robot class is used where control of the mouse and keyboard is needed. Add a throws declaration. Next, we find the element driver.findElement(By.name("s")).sendKeys This time, we are going to use ("json");

robot dot and the Robot class has over 10 methods. We are going to press the Enter key so we select keypress then KeyEvent. KeyEvent is also a class. It indicates the keystroke. The keystroke we want is VK underscore ENTER. There’s one more statement. We pressed the Enter key but have not released the Enter key. Therefore, our last statement is robot.keyRelease(KeyEvent.VK_ENTER); Let’s Run. Both Methods Passed. That’s it for pressing keys on the keyboard using the Selenium class and Robot class.

#RobotClass #SeleniumKeys #BeginnerSeleniumTutorials #SeleniumWebDriver


Смотрите видео ✔ How To Automate Pressing Keyboard Keys Using Selenium & Robot Class | (Video 67) онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Rex Jones II 20 Сентябрь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 3,829 раз и оно понравилось 21 людям.