Is it possible to make selenium identify an html button attribute and click on it. So whenever it finds a button attribute it clicks on it automatically. Because I always have to predict around how long it takes for the next button to appear and set time.sleep()
but many times it results in errors.
Asked
Active
Viewed 53 times
0

Abdalla Roda
- 607
- 1
- 6
- 13
1 Answers
1
Of coarse it is possible to identify an html button through an attribute and invoke click()
on it using Selenium.
But it won't be possible that, whenever a button is found through it's attribute, it can click on it automatically as:
- The prediction for how long to wait for the next button to be clickable should be part of your Test Plan or Test Architecture and should be part of the specifications.
- Further, using
time.sleep(n)
defeats the purpose of Automation and should be avoided at any cost.You can find a relevant detailed discussion in How to sleep webdriver in python for milliseconds
- Ideally, you need to remove the all the occurances of
time.sleep(n)
inducing WebDriverWait inconjunction with the expected_conditions.You can find a relevant detailed discussion in How to get rid of the hardcoded sleep()?

undetected Selenium
- 183,867
- 41
- 278
- 352