Anonymous
Ошибки при использовании функции селена в цикле for
Сообщение
Anonymous » 17 ноя 2024, 18:34
В настоящее время я тестирую сайт продажи билетов моей компании, поэтому, когда я запускаю этот код один раз, добавляя номер билета в Incident_ticket, все идет нормально, но поскольку я хотел выполнить массовую автоматизацию со многими билетами, я получаю случайный ошибки при попытке сделать это в цикле for со списком инцидентов_список.
Когда я выполняю код, первый элемент списка инцидентов_список обрабатывается правильно но следующие приводят к следующему ошибка:
Код: Выделить всё
An error occurred while processing ticket IN6519342: Message: element click intercepted: Element
[img]img_lookup.gif[/img]
is not clickable at point (335, 102). Other element would receive the click: ...
(Session info: chrome=130.0.6723.69)
Это код, сейчас я изучаю Selenium, поэтому буду рад любой помощи:
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
email = 'ryan.hills@company.com'
pwd = 'password123'
incidents_list = ["inc_0001", "inc_0002", "inc_0003", "inc_0004", "inc_0005", "inc_0006", "inc_0007", "inc_0008", "inc_0009"]
incident_ticket = 'inc_0010'
log_title = 'Note'
log_text = "Ticket it's beign resolved as low priority case, approved by PM."
timeout = 20
def ticket_processing(driver, incident):
try:
# WebDriverWait(driver, timeout).until(EC.invisibility_of_element((By.ID, "msgbox-dialog_inner_dialogwait")))
quicksearch_id = WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.ID, "quicksearch")))
# driver.execute_script("arguments[0].scrollIntoView();", quicksearch_id)
quicksearch_id.clear()
quicksearch_id.send_keys(incident)
quicksearch_id.send_keys(Keys.ENTER)
WebDriverWait(driver, timeout).until(EC.invisibility_of_element((By.ID, "msgbox-dialog_inner_dialogwait")))
urgency_id = WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, "m45bfddac-img")))
# driver.execute_script("arguments[0].scrollIntoView();", urgency_id)
WebDriverWait(driver, timeout).until(EC.invisibility_of_element((By.ID, "msgbox-dialog_inner_dialogwait")))
urgency_id.click()
p3_selection_id = WebDriverWait(driver, timeout).until(
EC.element_to_be_clickable((By.ID, "lookup_page1_tdrow_[C:1]_ttxt-lb[R:2]")))
p3_selection_id.click()
new_log_btn_id = WebDriverWait(driver, timeout).until(
EC.element_to_be_clickable((By.ID, "ma877f29e_bg_button_addrow-pb")))
# driver.execute_script("arguments[0].scrollIntoView();", new_log_btn_id)
new_log_btn_id.click()
new_log_title_id = WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, "m8b7047bb-tb")))
new_log_title_id.send_keys(log_title)
new_log_text_id = WebDriverWait(driver, timeout).until(
EC.element_to_be_clickable((By.ID, "mfc77772d-rte_iframe")))
new_log_text_id.send_keys(log_text)
save_btn_id = WebDriverWait(driver, timeout).until(
EC.element_to_be_clickable((By.ID, "toolactions_SAVE-tbb_image")))
save_btn_id.click()
print(f"Ticket {incident} processed successfully.")
except Exception as err:
print(f"An error occurred while processing ticket {incident}: {err}")
def main():
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless=new")
chrome_options.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.company.website.com")
id_element = driver.find_element(By.ID, "j_username")
id_element.send_keys(email)
pwd_element = driver.find_element(By.ID, "j_password")
pwd_element.send_keys(pwd)
pwd_element.send_keys(Keys.ENTER)
incident_id = WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, "FavoriteApp_INCIDENT")))
incident_id.click()
# function without for loop, everything goes fine
# ticket_processing(driver, incident_ticket)
# this is were I ge the errors
for incident in incidents_list:
ticket_processing(driver, incident)
if __name__ == '__main__':
main()
Спасибо
Подробнее здесь:
https://stackoverflow.com/questions/791 ... n-for-loop
1731857641
Anonymous
В настоящее время я тестирую сайт продажи билетов моей компании, поэтому, когда я запускаю этот код один раз, добавляя номер билета в Incident_ticket, все идет нормально, но поскольку я хотел выполнить массовую автоматизацию со многими билетами, я получаю случайный ошибки при попытке сделать это в цикле for со списком инцидентов_список. Когда я выполняю код, первый элемент списка инцидентов_список обрабатывается правильно но следующие приводят к следующему ошибка: [code]An error occurred while processing ticket IN6519342: Message: element click intercepted: Element [img]img_lookup.gif[/img] is not clickable at point (335, 102). Other element would receive the click: ... (Session info: chrome=130.0.6723.69) [/code] Это код, сейчас я изучаю Selenium, поэтому буду рад любой помощи: [code]from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC email = 'ryan.hills@company.com' pwd = 'password123' incidents_list = ["inc_0001", "inc_0002", "inc_0003", "inc_0004", "inc_0005", "inc_0006", "inc_0007", "inc_0008", "inc_0009"] incident_ticket = 'inc_0010' log_title = 'Note' log_text = "Ticket it's beign resolved as low priority case, approved by PM." timeout = 20 def ticket_processing(driver, incident): try: # WebDriverWait(driver, timeout).until(EC.invisibility_of_element((By.ID, "msgbox-dialog_inner_dialogwait"))) quicksearch_id = WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.ID, "quicksearch"))) # driver.execute_script("arguments[0].scrollIntoView();", quicksearch_id) quicksearch_id.clear() quicksearch_id.send_keys(incident) quicksearch_id.send_keys(Keys.ENTER) WebDriverWait(driver, timeout).until(EC.invisibility_of_element((By.ID, "msgbox-dialog_inner_dialogwait"))) urgency_id = WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, "m45bfddac-img"))) # driver.execute_script("arguments[0].scrollIntoView();", urgency_id) WebDriverWait(driver, timeout).until(EC.invisibility_of_element((By.ID, "msgbox-dialog_inner_dialogwait"))) urgency_id.click() p3_selection_id = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable((By.ID, "lookup_page1_tdrow_[C:1]_ttxt-lb[R:2]"))) p3_selection_id.click() new_log_btn_id = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable((By.ID, "ma877f29e_bg_button_addrow-pb"))) # driver.execute_script("arguments[0].scrollIntoView();", new_log_btn_id) new_log_btn_id.click() new_log_title_id = WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, "m8b7047bb-tb"))) new_log_title_id.send_keys(log_title) new_log_text_id = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable((By.ID, "mfc77772d-rte_iframe"))) new_log_text_id.send_keys(log_text) save_btn_id = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable((By.ID, "toolactions_SAVE-tbb_image"))) save_btn_id.click() print(f"Ticket {incident} processed successfully.") except Exception as err: print(f"An error occurred while processing ticket {incident}: {err}") def main(): chrome_options = Options() chrome_options.add_argument("--disable-extensions") chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--window-size=1920,1080") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--headless=new") chrome_options.add_argument("--disable-dev-shm-usage") driver = webdriver.Chrome(options=chrome_options) driver.get("https://www.company.website.com") id_element = driver.find_element(By.ID, "j_username") id_element.send_keys(email) pwd_element = driver.find_element(By.ID, "j_password") pwd_element.send_keys(pwd) pwd_element.send_keys(Keys.ENTER) incident_id = WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, "FavoriteApp_INCIDENT"))) incident_id.click() # function without for loop, everything goes fine # ticket_processing(driver, incident_ticket) # this is were I ge the errors for incident in incidents_list: ticket_processing(driver, incident) if __name__ == '__main__': main() [/code] Спасибо :D Подробнее здесь: [url]https://stackoverflow.com/questions/79192892/errors-when-using-selenium-function-in-for-loop[/url]