Analysis of web automation positioning element failure

problem analysis

  1. First of all - clear range - web automated testing

  2. Secondly - the express condition - elements are positioned correctly

  3. Then - a clear phenomenon - the positioning elements fail

  4. Finally - concluded

    1. The positioning element determine the attribute information is correct (has been determined correctly), but the service logic is correct is determined

    2. By the network / server / browser impact, the page loads too slowly will result in failure to locate, required by the elements waiting for treatment

    3. Whether the target element directly visible / need for mouse actions to show up

    4. After the default browser page load range sizes too small cause blocking some elements need to launch a browser maximized window

    5. 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

    6. 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

    7. 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

    8. 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

  1. 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 ()






  1. 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")
  1. 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 ()
  1. 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 ()
  1. 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 ()
  1. Processing alert


    # Close the pop-up
    Driver. Switch_to. Alert. Dismiss ()
  1. 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])
  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 ()

 

Guess you like

Origin www.cnblogs.com/ray-mr-huang/p/11518610.html