Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA Selenium WebElement overriding click() method

Is it good practice to override WebElement click() to add some wait functionality, because in some pages i need to click button and in some cases button is not loaded yet so i added wait to check if element is visible.

So My question is: Is it better to create abstract class which would implement WebElement and override click() method to add some wait functionality or it is better just to have plain wait only in specific pages ?

like image 806
Liolikas Bramanovas Avatar asked Mar 20 '26 10:03

Liolikas Bramanovas


1 Answers

As per the documentation Document Object Model (DOM) Level 2 HTML Specification click() method doesn't accepts any parameters, doesn't return any value and doesn't report any exceptions.

enter image description here

So, its clear that we can't override click() method in the first place.

But you can always write a customized user function to click on a WebElement along with certain types of waits. In these cases Selenium's in-built Explicit Wait i.e. the WebDriverWait comes to our help.


ExplicitWait

As per the documentation, an ExplicitWait is a code block you define, configure and implement for the WebDriver instance to wait for a certain condition to be met before proceeding for the next line of code. There are some methods that helps us to implement ExplicitWait that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one of the way ExplicitWait can be achieved.

You can find a detailed discussion on ExplicitWait in this discussion.

like image 120
undetected Selenium Avatar answered Mar 23 '26 00:03

undetected Selenium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!