(i) Webdriver
Webdriver provides many features and settings to interact with the browser, through Webdriver features and methods to interact with browser windows, warnings, frames, and pop-ups, and it also provides the ability to automate the browser navigation bar, set cookies, Screenshots and other features that facilitate our testing.
(ii) Webdriver functions and methods
Features/Properties |
Simple description |
Current_url |
Gets the URL address of the current page (Driver.current_url) The following are all in this way, driver refers to the browser driver instance. |
Window_handle |
Gets the handle of the current window |
Name |
Gets the browser name underlying the instance |
Orientation |
Get the current device's orientation |
Page_source |
Get the current page source code |
Title |
Gets the title of the current page |
Window_handles |
Gets the handle of all windows in the current session |
Method |
Simple description |
Close () |
Close the current browser window |
Back () |
One step back. |
Forward () |
Before further |
Get (URL) |
Access the URL and load the Web page to the current browser session |
Maximize_window () |
Maximize browser window |
Quit () |
Exits the current drive instance and closes all related windows |
Refresh () |
Refresh the current page |
Implicitly_wait () |
Wait time, unit of seconds |
Set_page_load_timeout () |
Sets the timeout wait time, in seconds, for a page to complete full load |
Set_script_timeout () |
To set the time-out for script execution |
(iii) webelement functions and methods
with webelement, you can interact with Web page elements, including text boxes, text fields, buttons, radio boxes, multiple boxes, tables, rows, columns, and Div.
Features/Properties |
Simple description |
Size |
Gets the element size (for example, element.size) In this way, element refers to one of the elements positioned |
Tag_name |
Gets the name of the label |
Text |
Gets the text value of the element |
Method |
Simple description |
Clear () |
Clear the contents of a text box or text field |
Click () |
Click on the element |
Get_attribute (name) |
Gets the attribute value of the element, name: The name of the property to get |
Is_displayed () |
Checks if the element is visible to the user |
Is_enabled () |
Checks if an element is available |
Is_selected () |
Checks whether the element is selected, primarily for radio boxes and check boxes |
Send_keys (value) |
Enter the text, value is the values to be entered |
Submit () |
Submit the form. If used on an element, the form to which the element belongs is submitted |
Value_of_css_property (Property_name) |
Gets the value of the CSS property, Property_name is the name of the CSS property |
(iv) Action form, text box, check box, radio button
Automate interactions with various HTML controls with Webelement, such as entering text in a text box, clicking a button, selecting a Radio box or check box, getting text and property values for an element, and so on.
For example, the automation of the blog Park registration function:
(Here is just an example ha, the direct copy is useless, the following code only locates part of the field (mailbox, Login and Registration button), and does not process the verification code, the Verification Code section later to study how to deal with it)
1 defTest_register_new_user (self):2 3 #Locate and click on the Register of the blog Park homepage4 5Login_area = Self.driver.find_element_by_css_selector ('#login_area')6 7Register = Login_area.find_element_by_link_text ('Register')8 9 Register.click ()Ten One #Check open page title is not ' user Registration-blog Park ' A -Self.asserttrue ('User Registration-Blog Park'==self.driver.title) - the #Locate registration page fields and register button - -User_email = self.driver.find_element_by_id ('Email') - +User_login_name = self.driver.find_element_by_id ('LoginName') - +REGISTER_BTN = self.driver.find_element_by_id ('submitbtn') A at #Check that the maximum allowable input characters and minimum input characters in a field are the same as expected - -Self.assertequal ('2', User_login_name.get_attribute ('Data-val-length-min')) - -Self.assertequal (' -', User_login_name.get_attribute ('Data-val-length-max')) - in #check that each field and button are visible to the user and available - toSelf.asserttrue (user_email.is_displayed () anduser_email.is_enabled ()) + - #Enter user Information the *User_email.send_keys ('[email protected]') $ Panax NotoginsengUser_login_name.send_keys ('Test') - the #Click the Register button + A Register_btn.click () the + #Check to see if a prompt for successful registration is displayed - $Self.asserttrue (Self.driver.find_element_by_css_selector ('P.txt-title.success-color'). Text = ='Registration Successful')
For example, you can use the following method to check whether the check box for the blog Park login page is selected
1 defTest_login (self):2 3... Omit the code that opens the login page (this paragraph is not commented#)4 5Automatic_login = self.driver.find_element_by_id ('Remember_me')6 7 #Check the login page check box, whether it is not selected by default8 9 Self.assertfalse (automatic_login.is_selected ())Ten One #Click to select the check box A -Automatic_login.click ()
Python+selenium Notes (vii): Webdriver and Webelement