2024-04-09 12:11:30 +08:00
|
|
|
import uuid
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException
|
2024-06-19 16:05:43 +08:00
|
|
|
from selenium.webdriver.common.by import By
|
2024-04-09 12:11:30 +08:00
|
|
|
|
|
|
|
def signup(URL, driver):
|
|
|
|
username = 'TestUser' + str(uuid.uuid1()).split('-')[0].title()
|
|
|
|
password = '[Abc+123]'
|
|
|
|
|
|
|
|
driver.get(URL)
|
|
|
|
|
2024-06-19 16:05:43 +08:00
|
|
|
try:
|
|
|
|
# Click the register link
|
|
|
|
register_link = WebDriverWait(driver, 10).until(
|
|
|
|
EC.element_to_be_clickable((By.LINK_TEXT, '注册'))
|
|
|
|
)
|
|
|
|
register_link.click()
|
|
|
|
|
|
|
|
# Fill the registration form
|
|
|
|
username_field = WebDriverWait(driver, 10).until(
|
|
|
|
EC.presence_of_element_located((By.ID, 'username'))
|
|
|
|
)
|
|
|
|
username_field.send_keys(username)
|
2024-04-09 12:11:30 +08:00
|
|
|
|
2024-06-19 16:05:43 +08:00
|
|
|
password_field = driver.find_element(By.ID, 'password')
|
|
|
|
password_field.send_keys(password)
|
2024-04-09 12:11:30 +08:00
|
|
|
|
2024-06-19 16:05:43 +08:00
|
|
|
confirm_password_field = driver.find_element(By.ID, 'password2')
|
|
|
|
confirm_password_field.send_keys(password)
|
|
|
|
|
|
|
|
# Click the register button
|
|
|
|
register_button = driver.find_element(By.CLASS_NAME, 'btn')
|
|
|
|
register_button.click()
|
|
|
|
|
|
|
|
# Handle possible alert
|
|
|
|
try:
|
|
|
|
WebDriverWait(driver, 1).until(EC.alert_is_present())
|
|
|
|
alert = driver.switch_to.alert
|
|
|
|
alert.accept()
|
|
|
|
except (UnexpectedAlertPresentException, NoAlertPresentException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
return username, password
|
2024-04-09 12:11:30 +08:00
|
|
|
|
2024-06-19 16:05:43 +08:00
|
|
|
except Exception as e:
|
|
|
|
print(f"An error occurred: {e}")
|
|
|
|
return None, None
|