2

I am trying to complete a do-while loop with the below code. We are waiting for a report to process, and it only shows on the webpage once completed and after clicking the retrieve button. The code,

# Go to list and click retrieve
driver.find_element(By.CSS_SELECTOR, "#j_idt40Lbl").click()
time.sleep(20) # takes a while for their side to run
retrieve = driver.find_element_by_css_selector("#tab_reportList\:listPgFrm\:listPgRetrBtn")
retrieve.click() ### Do this action ###
time.sleep(5)
retrieve.click()
time.sleep(5)
retrieve.click()
time.sleep(3)

# Click report file
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#tab_reportList\:listPgFrm\:listDataTable_0\:0\:reportLink"))).click() 
### Until this is visible ###
1
  • does element #tab_reportList\:listPgFrm\:listDataTable_0\:0\:reportLink is presented there even before it becomes visible? Commented Jan 31, 2022 at 14:14

1 Answer 1

3

In case the element finally becoming visible is not initially presents on the page your code can be something like this:

driver.find_element(By.CSS_SELECTOR, "#j_idt40Lbl").click()
time.sleep(20)
while True:
    driver.find_element_by_css_selector("#tab_reportList\:listPgFrm\:listPgRetrBtn").click()
    time.sleep(5)
    if driver.find_elements_by_css_selector("#tab_reportList\:listPgFrm\:listDataTable_0\:0\:reportLink"):
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#tab_reportList\:listPgFrm\:listDataTable_0\:0\:reportLink"))).click()
        break

Hardcoded sleeps of 5 and 20 seconds are not looking good. If possibly they should be changed by Expected Conditions explicit waits

Sign up to request clarification or add additional context in comments.

2 Comments

if(driver.find_elements_by_css_selector("#tab_reportList\:listPgFrm\:listDataTable_0\:0\:reportLink")): - In python we do not need those if parentheses.
Right, I just copied the original code to make it working. But I will correct that, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.