problem analysis
-
First of all - clear range - web automated testing
-
Secondly - the express condition - elements are positioned correctly
-
Then - a clear phenomenon - the positioning elements fail
-
Finally - concluded
-
The positioning element determine the attribute information is correct (has been determined correctly), but the service logic is correct is determined
-
By the network / server / browser impact, the page loads too slowly will result in failure to locate, required by the elements waiting for treatment
-
Whether the target element directly visible / need for mouse actions to show up
-
After the default browser page load range sizes too small cause blocking some elements need to launch a browser maximized window
-
By front-end impact of dynamic loading technology, the page dynamically load data sometimes need to listen to scroll action (long page flip), you need to scroll bar
-
During operation of the page in the window can also affect the elastic alert page frame positioning and operation, it is necessary to process alert
-
Portion of the page after clicking a hyperlink will open in a new window, the target element in the new window, the need for window switch
-
Received front page framework affect page content may be in the frame sub-pages, we need to frame switching
-
summary of the issue
Since the answer to this question clearly requires a lot of Selenium API for common operations, so the answer to this question should pay special attention to code implementation
-
Business logic
# Note that the order of business logic - Open Home log in directly operating
# 2. Enter the URL
# drive object calls get ( "protocol: // the URL of")
Driver. GET ( "http://www.xxx.com") # 3. business operation # landing operation to enter a user name / password / code Driver. find_element_by_id ( "username"). send_keys ( "xxxxxx") Driver. find_element_by_id ( "password"). send_keys ( "123456") Driver. find_element_by_id ( "verify_code"). send_keys ( "8888") Driver. find_element_by_name ( "sbtbutton"). the Click ()
-
Elements waiting
# Hard to wait for
# use sleep, suspend program execution
Time. SLEEP ( 3)
Driver. Find_element_by_id ( "q"). Send_keys ( "the iPhone") # Implicit wait - set up once - for a global - all elements positioned # selenium.common.exceptions.NoSuchElementException # call - using the browser driven object call argument - the long second waiting . driver implicitly_wait ( 10) . driver find_element_by_id ( "Q"). send_keys ( "iPhone") # explicit wait - for specified element positioning - positioning the failure is thrown # selenium.common.exceptions.TimeoutException # WebDriverWait instantiate an object class, the object class is called WebDriverWait an until the wait = WebDriverWait ( Driver, timeout = 10,
poll_frequency=1)
userA_element = wait.until(lambda d: d.find_element_by_id("q"))
userA_element.send_keys("iphone")
-
Mouse movements
Examples of the operation of a # chain objects
# object calls the action method of operation of the chain --move_to_element (Object target element)
# chain operation object calls perfom ()
ActionChains ( Driver). Move_to_element ( Driver. Find_element_by_class_name ( "UG-Cart")). Perform ()
-
Maximized window
1. Open the browser #
# instance of the browser driven
# obj = class name ()
Driver = the webdriver. The Chrome ()
# maximize the browser window
Driver. Maximize_window ()
-
Scroll bar
# Scroll bar
Driver. Execute_script ( "window.scrollTo (0,100000)")
# Click back to the top of the
Driver. Find_element_by_class_name ( "ico-slidebar4"). The Click ()
-
Processing alert
# Close the pop-up
Driver. Switch_to. Alert. Dismiss ()
-
Window switch
# Switching window - a general rule is the new default to the last window handle
Driver. The switch_to. Window ( Driver. Window_handles [ - . 1])
-
frame switch
# Frame switching Home - sub-pages
driver.switch_to.frame (driver.find_element_by_tag_name ( "iframes."))
# Clicks to cart settlement
driver.find_element_by_link_text ( "go cart settlement") .click ()
# frame switching sub-pages - - Home
driver.switch_to.default_content ()