from random import random
import random
import select
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
count = 200
for i in range(200):
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)
# click Edit Appointment Hours button
Button = driver.find_element(By.XPATH, "//*[text()=' Edit Appointment Hours ']")
Button.click()
time.sleep(1)
# click Select Outlet dropdown
element = driver.find_element(By.CSS_SELECTOR,".multiselect.col-md-4 .multiselect__tags")
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(1)
element.click()
outlet_options = driver.find_elements(By.XPATH,".//*[contains(@class,'multiselect col-md-4')]//span[@class='multiselect__option']")
option_to_select = random.randint(1, 3)
print("option to select in Select outlet - ", option_to_select)
driver.find_element(By.XPATH, "(.//*[contains(@class,'multiselect col-md-4')]//span[@class='multiselect__option'])[" + str(option_to_select) + "]").click()
time.sleep(1)
time_to_select = random.randint(1, 3)
print("time to select: ", time_to_select)
select = Select(driver.find_element(By.XPATH,".//*[@name='predefinedHours']"))
select.select_by_index(time_to_select)
time.sleep(1)
driver.find_element(By.XPATH,"//*[@id='edit-hours']/div[4]/button").click()
- 我运行了上面的代码,它没有问题。但是当我试图将循环设置得更高时,它显示了错误NoSuchElementException:消息:没有此元素:找不到元素:我想知道为什么会显示错误,因为它可以运行良好,在早期阶段,但崩溃后。希望有人可以帮助我解决错误。我测试了几次,最高循环是20左右,它崩溃。谢谢,祝你有一个美好的一天 *
1条答案
按热度按时间gfttwv5a1#
尝试使用Expected conditions而不是
time.sleep
(或同时使用两者以获得额外的安全性)例如: