You have two lines of code of which the second is fully redundant (because the first already does the same, and more).
I do agree that defining a new WebdriverWait every time isn't very readable too.
Thus, the solution could be simple:
- define a WebdriverWait one time at framework level (static if need be)
- create a helper method that uses this variable
In my C# framework, for example, I can simply use
Furthermore, if you read my response in another of your questions, you will notice the phrase
I never have to add a wait or a clear() in my PageObjects again (when dealing with individual elements)
Because when using framework wrapper methods for WebElement actions, you can put in them what you want - even assertions per your question (see my example below). The main advantage is highly reduced and very clean code in Page Objects and consistency across Page Objects in dealing with elements. High-level example for entering text with C# extension methods (but in other languages you will probably find different syntax to achieve the same).
When using PageFactory to initialize the elements, my only line of code would be this (even though the field is not necessarily loaded at this point)
All the waiting and additional actions (clearing the element first) are done behind the scenes. The waiting works because of using PageFactory and catching the
NoSuchElementException in the framework (with a
public void SetText(this IWebElement element, string text)
// first, wait until element is visible using another extension method
// in this method a WebDriverWait is used, so it only returns once found
// if you want to, assert visibility again
// it's only defined once here in the framework so your Page Objects stays clean
// then enter text