Selenium2+python Automation 12-Operating elements (keyboard and mouse events) "Reprint"

Source: Internet
Author: User

Objective

在前面的几篇中重点介绍了一些元素的到位方法,到位到元素后,接下来就是需要操作元素了。This article summarizes some of the common operational element methods of Web pages, which can be collectively referred to as behavioral events
有些web界面的选项菜单需要鼠标悬停在某个元素上才能显示出来(如百度页面的设置按钮)。

First, simple operation

1. Click the (left mouse button) page buttons: click ()

2. Please empty input box: Clear ()

3. Input string: Send_keys ()

4. Open the Test Tribe forum, click the magnifying glass search icon, generally in order to ensure the correctness of the input, you can first empty the input box, and then enter the search keywords


 

Ii. Submission of Submit form

1. In the previous Baidu search case, enter the keyword, you can directly press ENTER to search, you can also click search button search.

2.submit () typically used to simulate the ENTER key

3. But the forum search, if the use of submit, will be error, but there is no search click button, how to do?


Three, keyboard operation

1.selenium provides a full set of analog keyboard operation events, before the Submit () method if not, you can try to simulate keyboard events

2. The keyboard module must be imported first: from Selenium.webdriver.common.keys import keys

3. Analog ENTER key, can be used Send_keys (Keys.enter)

4. Other common keyboard operations:

Keyboard F1 to F12:send_keys (KEYS.F1) to change the F1 to corresponding shortcut keys

Copy Ctrl+c:send_keys (Keys.control, ' C ')

Paste Ctrl+v:send_keys (Keys.control, ' V ')

Select All Ctrl+a:send_keys (Keys.control, ' A ')

Cut Ctrl+x:send_keys (Keys.control, ' X ')

TAB key Tab:send_keys (Keys.tab)

Here is just a list of some common, of course, except for keyboard events, there are mouse events


Four, mouse hover events

1. Mouse can not only click (click), mouse and other actions, such as: mouse hover over an element, the mouse right click, mouse down a button dragged to

2. Mouse events need to import modules first: from Selenium.webdriver.common.action_chains import actionchains

Perform () perform behavior in all Actionchains

Move_to_element () mouse hover

3. Here is an example of the Baidu Page Setup button

4. In addition to the commonly used mouse hover events, there are

Right-click the mouse: Context_click ()

Double mouse: Double_click ()

According to gourd painting scoop, replace the corresponding mouse event in the above case can be

Selenium provides a complete set of mouse and keyboard behavior events, the function is quite powerful drops. The next article describes how to handle multi-window scenarios.

Selenium2+python Automation 12-Operating elements (keyboard and mouse events) "Reprint"

Related Article

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.