【发布时间】:2023-01-11 01:01:48
【问题描述】:
from random import Random
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome('chromedriver')
driver.get('https://devbusiness.tunai.io/login')
time.sleep(2)
driver.maximize_window()
# Create variables for login credentials.
username = driver.find_element(By.NAME, "loginUsername");
username.send_keys("kevin@tunai");
password = driver.find_element(By.NAME, "loginPassword");
password.send_keys("123456");
login = driver.find_element(By.XPATH,"//*[@id='app']/div/div/div/div/div/div[2]/form/div[4]/button");
login.submit();
time.sleep(1)
driver.get("https://devbusiness.tunai.io/dashboard/my_salon_appointment")
time.sleep(1)
Button = driver.find_element(By.XPATH,"//*[@id='page-content']/div/div[2]/div/div/div[1]/div/div[1]/button")
Button.click()
time.sleep(1)
# trigger with other element first, add this code
element = driver.find_element(By.XPATH,"//*[@id='edit-hours']/div/div/div[2]")
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(1)
element.click()
# outlet button
outlet_button = driver.find_element(By.XPATH,"//*[@id='edit-hours']/div/div/div[1]")
# An kevin@tunai in the
outlet_select = driver.find_element(By.XPATH,"""//*[@id="edit-hours"]/div/div/div[3]/ul/li[2]/span""")
# Click category button to show list.
outlet_button.click()
# Click on category you want select.
outlet_select.click()
time.sleep(3)
select = Select(driver.find_element(By.XPATH,"//*[@id='edit-hours']/div[1]/select"))
select.select_by_index(3)
time.sleep(3)
driver.find_element(By.XPATH,"//*[@id='edit-hours']/div[4]/button").click()
我正在尝试执行 Web 自动化测试,现在我一直在研究如何从出口和时间列表中选择随机值。有点没主意了,希望有人能帮忙,在此先感谢并祝你有美好的一天。
【问题讨论】:
-
你好!我对您的问题有一个澄清:您是否能够找到完整的选项列表,但不知道如何随机选择一个选项,或者您是否正在寻找一种方法来自行阅读整个选项列表?
-
我没能找到完整的选项列表,我现在想做的只是从列表中选择随机选项。
标签: python selenium select random optional-values