1. Element positioning

Explain the simple script from the previous section. What does the blue line mean?

What we’re going to do is

1. Visit Youdao Website

2 Enter the content to be queried in the word text box

3. Click Query Button

4. After the page is displayed, exit the browser

Login must be able to see, but what is the meaning of the blue line below, because the input box and the search button are in the front-end framework, so we can use the front-end framework code elements to locate the part we need to use and complete the simulation interaction.

I don’t know much about front-end frameworks, but to locate an element you have to give enough information and unique element content, like the ELEMENT’s GUID. I don’t really understand front-end stuff, but I can use it. Follow me.

Developer mode we must be familiar with the following:

As shown, the code is shown in plain text.

There is a small mouse arrow on the left side of the viewer!! It’s kind of exciting to see this because it’s like we need this thing to simulate location to the location of the element that we need, otherwise all this code, visual retrieval…

1. The upper red line area is the user behavior area we want to simulate, so click the mode just now to jump to the blue code in the lower red box area.

2. Then, the blue code has a lot of content but there seems to be a name called ID! By the way,ID is an attribute that identifies an element.

3. I am using the method just now to locate and translate button, this time my mentality is broken, just write a TAB name how to do this how to identify the difference, use the most simple and crude!! Xpath — right click copy — xpath.

The preparatory work has been finished.

PS: In addition, there are eight elements to locate, but it is ok to locate the only element.

Id positioning

The name to locate

The class location

The tag positioning

The link to locate

Partial link location

Xpath positioning

The CSS positioning

There are By sentence, but the effect is the same as the previous eight, you can baidu yourself.

Xpath is an absolute path, so if you find an absolute path to a web element, this method will work.

Python code can be written like this:

Find_element_by_XXX (“YYY”) XXX indicates any of the eight locating methods or combinations. YYY indicates the locating attribute name. Send_keys (“”) in the script simulates typing and click() simulates clicking.

That should make sense.

I have a bold idea to operate a wave 1024 like this and then climb down all the XXX hd code so that I can be in the hospital in less than a month.

Control the browser

To enjoy the remote X sense, you can control the window size, forward and backward refresh, close open clear text……

Run, successful.

Enslave the browser, to continue to enslave the mouse

Click () used before is the simulated left mouse click behavior. In WebDriver, these mouse operation methods are encapsulated in ActionChains.

ActionChains common methods:

· Perform () performs all actions stored in ActionChains;

· context_click () right click;

, double_click () double click;

Similar to above

· drag_and_drop (source and target) drag;

Target: indicates the target element released by the mouse

· MOVE_to_element (): hover;

Four. Slave keyboard keyboard operation:

Send_keys (keys.back_space) delete key send_keys(keys.space) SPACE key send_keys(keys.tab) TAB key etc