0

click() property in python(selenium) works only when time.sleep() added.
Main script already has implicit wait specified at the start.
Can someone please share a reason as to why this may be happening.

Below is the python code that I have written.

time.sleep(10)
driver.find_element(By.ID, 'tab-all').click()
furas
  • 134,197
  • 12
  • 106
  • 148
  • Welcome to Stack Overflow. You will have a better experience here if you take the [Tour](https://stackoverflow.com/tour) and read through [How To Ask](https://stackoverflow.com/help/how-to-ask), then edit your question with the details needed to create a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Please attached the link to the website also – mpx Jul 13 '20 at 03:33
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Jul 13 '20 at 09:05

3 Answers3

1

time.sleep() is a bad practice. This happens because selenium tries to click a button before it is visible. In order to click the button immediately after its spotted, use this code:

from selenium.webdriver.support import expected_conditions as EC

myElem = WebDriverWait(browser,delay).until(EC.presence_of_element_located((By.ID, 'tab-all')))
myElem.click()

If the above code isn't very clear to you, this will surely help you.

RushiSrinivas.K
  • 171
  • 2
  • 11
0

Try this:

from selenium import webdriver
webdriver.support.ui.WebDriverWait(driver, 10).until(lambda driver:driver.find_element(By.ID, 'tab-all').click())
0

This is now solved .... I figured out that although the element was visible but it was not fully loaded ..... It used take some time to fully load ... It earlier used to partial load example as 'All (11)' and then full load to 'All (123434)' hence I was not able to click on it .... Now I wait and check if the text has been changed from the initial load and then I click on it.