WEB
Common operations of WebElement and WebDriver in automated tests

I. Use of WebElement
1. Use browser.find_element_by_xx() to get a WebElement instance


The hierarchy lookup is done by calling the above API with the obtained instance
2. Browser.find_elements_by_xx () is used to obtain a list of elements that are WebElement instances
Some common operations of WebDriver
1. Browser. curret_URL: Obtains the URL of the currently loaded page
2. Browser.close () : Closes the current window. If the current window is the last one, the browser will close
3. Browser.quit () : Close all Windows and stop ChromeDriver execution
4. Browser.add_cookie (cookie_dict) : Adds a cookie to the current session


Browser.get_cookie (name) : Gets the execution cookie


Browser.get_cookies () : Gets all cookies


Driver. Add_cookie ({” name “:” foo “, “value” : “bar”}) driver. Add_cookie ({” name “:” foo “, “value” : “bar”, “path” : ‘/’}) driver. Add_cookie ({” name “:” foo “, “value” : “bar”, “path” : “/”, “secure” : True})
Browser.delete_all_cookies () : Deletes all cookies of the current session


Browser.delete_cookie (name) : deletes the specified cookie
6. Browser.back () : equivalent to the browser’s back history
7. Browser.forward () : represents the forward history of the browser
Browser.execute_script (script, *args) : Synchronously executes JS scripts


Browser.execute_async_script (script, *args) : Asynchronous execution of JS scripts
9. Browser.get (URL) : Loads the URL in the current window
10. Browser.refresh () : Refreshes the current page
11. Browser.current_window_handle: The handle of the current window, which is equivalent to a pointer to the current window
12. Browser.window_handles: A list of all Windows that are already open in the current browser
13. Browser. switch_TO_window (WINDOW_handle) : Switches the window pointed to by window_handle
14. Browser. title: title of the current page
15. Browser. name: indicates the name of the current browser
Three, WebElement some common operations
1. Webele.clear () : Clear the content of an element, if it is a text element
2. Webele.click () : Click the current element
3. WebEle,is_displayed() : Indicates whether the current element can be displayed
4. Webele.is_enabled () : Whether the current element is disabled, for example, clicking on some elements is often disabled
5. Webele.is_selected () : Whether the current element is selected, the text input box content
6. Webele.send_keys (*value) : Simulates keyboard events to the current element
7. Webele.submit () : Submit the form
8. Webele. tag_name: the tag name of the current element
9. Webele.text: Contents of the current element
10. Webele.get_attribute (name) : Gets the value of the current element’s execution attribute