Validation of selenium + chrome driver common slider


  • Using selenium to realize automatic login
  • Tidy up your ideas
    Get the ID of the password input box of the account - > fill in the account - > fill in the password - > appear a slider - > slide over the slider - > Click login


  • The process of getting the input box id is not introduced any more, but the element of'iframe', for example:

    <iframe src="" frameborder="0" id="iframe_id">
    <input type="text" id="user_name">
    <input type="text" id="password">
    <button id="login">Sign in</button>

    The data in the iframe tag can not be obtained directly, so it needs to be switched once to get the data.

    # Switch to iframe
    # Clear the account box
    # Fill in account number
    # Fill in the password
  • When filling in the password, there is a slider verification. First, don't rush to make the slider, sleep for a while, then manually pull the slider, surprise comes.

  • Maybe the technology of a treasure is relatively high-end. No matter how you pull it, it will fail. It's amazing. The reason is that the current page is opened by selenium by using some js method. So it's considered a crawler. It's impossible to let you go.


  • You need to modify the contents of the chromedriver file

    Change'cdc_asdjflasutopfhvcZLmcfl'to any character with the same number of characters, and execute in root mode, otherwise the file will be damaged, remember to backup.
    For details, please refer to: stackoverflow-selenium-with-chromedriver

  • Problem solving, start automatic slider operation, normal to get the slider id to operate, but I want to use a strange way.

    # Slide verification
    from selenium.webdriver.common.action_chains import ActionChains
    # Slider validation, assuming that the id of the slider is not available
    def the_slider_validation(driver):
        builder = ActionChains(driver)
        # Get the button to log in
        l = driver.find_element_by_id("login")
        # Clear up the previous action
        # Calculate the trajectory of the slider movement, 300 is the moving distance.
        track = move_mouse(300)
        # Move to the 35-pixel position on the login button (where the slider is), and locate the slider according to the login button
        builder.move_to_element_with_offset(l, 0, -35)
        # Click on the left button, do not release
        # Start to generate trajectories
        for i in track:
            builder.move_by_offset(xoffset=i, yoffset=0)
        # Release the left key to perform the action in for
    # Mouse movement
    def move_mouse(distance):
        remaining_dist = distance
        moves = []
        a = 0
        # Acceleration, faster and faster.
        while remaining_dist > 0:
            span = random.randint(15, 20)
            a += span
            remaining_dist -= span
            if sum(moves[:-1]) > 300:
        return moves
  • Verify that it passes, click login, or fail to retry


Links to this article: Time No Blog - selenium + chrome driver common slider verification

Tags: Selenium

Posted on Thu, 10 Oct 2019 03:22:13 -0700 by skylark2