0

In my project I am using Implicitly_wait(timeout) and

WebDriverWait(browser, 15).until(
        EC.element_to_be_clickable((By.XPATH, 'locator'))

for waiting of elements which not visible or not on the page.

I have element on the page which size=0 in the first seconds. Now, for click on this element when size>0 I am using time.sleep(), because implicit wait and expected conditions not working for this case(element on the page and it clickable).
Please, tell me, can I use some more stable method for waiting this element?
time.sleep is not option for me, because I have a lot of such elements.

Prophet
  • 32,350
  • 22
  • 54
  • 79
Alex
  • 9
  • 2
  • You shouldn't use implicit wait together with the explicit wait: https://stackoverflow.com/questions/60762906/selenium-is-it-okay-to-mix-implicit-wait-and-explicit-wait-like-this – Mate Mrše Apr 28 '21 at 11:30

1 Answers1

1

Try using this:

def wait_for_element_visibility(self, waitTime, locatorMode, Locator):
     element = None
     if   locatorMode == LocatorMode.ID:
          element = WebDriverWait(self.driver, waitTime).\
                  until(EC.visibility_of_element_located((By.ID, Locator)))
     elif locatorMode == LocatorMode.NAME:
          element = WebDriverWait(self.driver, waitTime).\
                  until(EC.visibility_of_element_located((By.NAME, Locator)))
     elif locatorMode == LocatorMode.XPATH:
          element = WebDriverWait(self.driver, waitTime).\
                  until(EC.visibility_of_element_located((By.XPATH, Locator)))
     elif locatorMode == LocatorMode.CSS_SELECTOR:
          element = WebDriverWait(self.driver, waitTime).\
                  until(EC.visibility_of_element_located((By.CSS_SELECTOR, Locator)))
     else:
         raise Exception("Unsupported locator strategy.")
     return element

credits for the author

Prophet
  • 32,350
  • 22
  • 54
  • 79