Python + Selenium Automated Test Life Restart Simulator


Recently, there is a H5 game that is particularly popular, called "Life Restart Simulator". This game uses a black humorous form of ridicule to randomly generate a list of your life events. At the beginning, you can also extract talents and add points, which is full of fun.

Because of the excessive traffic on the official website, some friends have access to white screens and webpage failures. The editor is here to post an online link to the latest life restart simulator:

After restarting my life, I wondered if I could write a script to automate the running of this game. Because it is a pure web operation, I can use the automated test artifact combined with Python and Selenium to test it.


Because this game is essentially a series of web page operations, it is relatively simple to implement, just as a review of the basic element operations of Selenium. Children's shoes who want to get started with Python can check it out.

I have previously written a Python+Selenium automated test synthesis big watermelon which can also be used for learning.

Note: This is not an intelligent script to improve game scores, but just a case study to demonstrate automated testing to help everyone better understand the usage of selenium.

Development Environment

  1. Download and install Python
  2. Install pip
  3. Install Selenium and browser webdriver

The mac platform is different from the windows platform. Pay attention to the environment when installing. The details are not listed here, just google it.

If you download Python or pip installation is slow, you can refer to this blog post to speed it up.

Install py module artifact


After the environment is ready, copy the following code directly to the .py file, such as, and execute python can start webdriver to run the automated life restart simulator.

# -*- coding: UTF-8 -*-

# Google Chrome Driver
from selenium import webdriver

# sleep module, let the program stop running down
from time import sleep

# Import the random (random number) module
import random

# Load Google Chrome in mobile mode
mobile_emulation = {'deviceName':'iPhone 5'}
options = webdriver.ChromeOptions()
options.add_experimental_option("mobileEmulation", mobile_emulation)

driver = webdriver.Chrome(chrome_options=options)

# Set browser size

# Open the set URL

# Implicit wait

# Click to reopen now
restart = driver.find_element_by_id('restart')


# Click 10 consecutive draws


# Random 1-10 numbers, used to draw talent cards

randomOne = random.randint(1,3)
randomTwo = random.randint(4,6)
randomThree = random.randint(7,10)

# Find the three talent card buttons and click
driver.find_element_by_css_selector("#talents li:nth-of-type("+ str(randomOne) +")").click()
driver.find_element_by_css_selector("#talents li:nth-of-type("+ str(randomTwo) +")").click()
driver.find_element_by_css_selector("#talents li:nth-of-type("+ str(randomThree) +")").click()

# Click to confirm: "Please select 3"


# Click Random Assignment


# Start a new life

# Continue to click on the life event list area until the content in the list area no longer increases, which means that life is over
isOver = False # end flag
life = 0 # The length of the previous life

while(not isOver):
    # Click to list life events
    print('click once'+str(life))


    # Note that you must use find_elements, not find_element, otherwise the len method will report an error
    li = driver.find_elements_by_css_selector("#lifeTrajectory li")

    currt_life = len(li)

    # If the list continues to increase, continue to click; once it does not increase, it means you are dead
    if currt_life> life:
        life = currt_life
        isOver = True

# Click on Life Summary



The program is relatively sketchy, and many details are not perfect yet, but it can be used as a reference for small cases, and everyone is welcome to criticize and point out problems. There will be time to share more useful test scripts and fun games later.