· 9 years ago · Jan 09, 2017, 08:26 PM
1"""
2 This code would automate a test at the gmail.com
3"""
4
5from selenium import webdriver
6from selenium.webdriver.common.keys import Keys
7from selenium.webdriver.common.by import By
8import time
9import random
10
11with open("names.txt") as f:
12 names = [line.rstrip('\n') for line in f]
13
14with open("dates.txt") as f:
15 dates = [line.rstrip('\n') for line in f]
16
17with open("ssn.txt") as f:
18 ssn = [line.rstrip('\n') for line in f]
19
20gender = ["Masculino","Feminino"]
21
22"""Create a Firefox browser instance."""
23driver = webdriver.Chrome()
24
25"""Open the url of elearning."""
26driver.get("http://localhost:8080/index.php")
27driver.implicitly_wait(3)
28
29"""Caixa Entrada""" #clica em registar aluno
30driver.find_element_by_xpath("/html/body/div/form/p/a").click()
31time.sleep(3)
32
33
34#Name:
35inputElement = driver.find_element_by_xpath("/html/body/form/ul/li[1]/input")
36inputElement.send_keys(random.choice(names))
37#Surname:
38inputElement = driver.find_element_by_xpath("/html/body/form/ul/li[2]/input")
39inputElement.send_keys(random.choice(names))
40#SSN:
41inputElement = driver.find_element_by_xpath("/html/body/form/ul/li[3]/input")
42inputElement.send_keys(random.choice(ssn))
43#Birthdate:
44inputElement = driver.find_element_by_xpath("/html/body/form/ul/li[4]/input")
45inputElement.send_keys(random.choice(dates))
46#GPA:
47inputElement = driver.find_element_by_xpath("/html/body/form/ul/li[5]/input")
48inputElement.send_keys(random.randint(0, 20))
49#Gender:
50inputElement = driver.find_element_by_xpath("/html/body/form/ul/li[6]/select")
51inputElement.send_keys(gender)
52
53#Criar:
54driver.find_element_by_xpath("/html/body/form/ul/li[7]/input").click()
55time.sleep(2)
56#driver.close()