It looks like this and it doesn't work any other way.
Which other functions for waiting for an element on the page and waiting for the page to load could I use?
buttonEnter = driver.find_element(By.XPATH,'/html/body/div/div[1]/div[1]/div/div/form/div[3]/button')
buttonEnter.click()
time.sleep(10)
buttonLeftMenu = driver.find_element(By.XPATH, "/html/body/div[1]/div[2]/div[1]/div[1]/div/div/button")
buttonLeftMenu.click()
buttonItemSelection = driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[2]/div[1]/div[2]/div/div/div/ul/li[6]")
buttonItemSelection.click()
time.sleep(10)
buttonItemLoyaltyPrograms = driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[2]/div[1]/div[2]/div/div/div/ul/li[6]/div/ul/li[4]/a")
buttonItemLoyaltyPrograms.click()
time.sleep(10)
searchLoyaltyPrograms = driver.find_element(By.XPATH,"/html/body/div/div[2]/div[1]/div[2]/div[2]/form/div[2]/div/div/div/div[1]/div[1]/div/input")
searchLoyaltyPrograms.send_keys("Шаблонная программа")
buttonSearh = driver.find_element(By.XPATH, "/html/body/div/div[2]/div[1]/div[2]/div[2]/form/div[2]/div/div/div/div[1]/div[1]/div/input")
buttonSearh.click()
I tried it like this, swears that it cannot find such an element and crashes:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, "loaded")))
Using time.sleep in test automation is generally considered a bad practice for several reasons:
1. Unreliable timing: Using a fixed delay with time.sleep assumes that a certain action will always take the same amount of time. However, the execution speed of tests can vary depending on factors such as system load, network latency, or the performance of the application under test. This can lead to tests failing due to incorrect timing assumptions.
2. Increased test execution time: time.sleep adds a fixed delay to your test script, even if the element or condition you are waiting for becomes available earlier. This unnecessarily increases the overall execution time of your tests.
3. Poor maintainability: If the application under test undergoes changes, such as UI updates or improvements in performance, using fixed sleep delays may cause your tests to become unreliable. You would need to manually update the sleep durations, which can be time-consuming and error-prone.
To overcome these issues, it's recommended to use explicit waits in test automation. Explicit waits allow you to wait for specific conditions to be met before proceeding with the test. They are more reliable and provide better control over the timing of your tests. Selenium WebDriver provides the WebDriverWait class for implementing explicit waits.
Here's an example of using explicit waits instead of time.sleep in Python with Selenium WebDriver:
In this code, we use WebDriverWait to wait for the target element to be present before proceeding with further actions. The EC.presence_of_element_located expected condition checks if the element is present in the DOM. The WebDriverWait instance will keep polling the DOM until the element is found or a timeout occurs.
Using explicit waits in this way provides more reliable and efficient synchronization between your test script and the application under test, without relying on fixed sleep durations.
Here's a list of commonly used explicit waits:
presence_of_element_located: Waits for an element to be present in the DOM.
visibility_of_element_located: Waits for an element to be visible.
invisibility_of_element_located: Waits for an element to be invisible.
element_to_be_clickable: Waits for an element to be clickable (visible and enabled).
text_to_be_present_in_element: Waits for specific text to be present in an element.
title_contains: Waits for the page title to contain specific text.
alert_is_present: Waits for an alert to be present.
These are just a few examples of the explicit waits available in Selenium WebDriver. You can find more explicit wait conditions in the expected_conditions module documentation:
https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.support.expected_conditions