Now my tests look like this

wait.until(ExpectedConditions.elementToBeClickable(webSite.mainPage().PlusInsideSection)); webSite.mainPage().PlusInsideSection.click(); wait.until(ExpectedConditions.elementToBeClickable(webSite.mainPage().ElementParagraph)); webSite.mainPage().ElementParagraph.click(); wait.until(ExpectedConditions.elementToBeClickable(webSite.mainPage().Plus)); webSite.mainPage().Plus.click(); wait.until(ExpectedConditions.elementToBeClickable(webSite.mainPage().AddPrebuilt)); webSite.mainPage().AddPrebuilt.click(); wait.until(ExpectedConditions.elementToBeClickable(webSite.mainPage().AddBanner)); webSite.mainPage().AddBanner.click(); 

That is, waiting has to write before each action. Is there a way to somehow wrap / override the click () method so that you do not have to manually set the wait each time? If so, how to implement it?

  • YaP kept a secret. - Nakilon
  • Completed question - Pavel Bobrov

1 answer 1

Well, first, the until method and so returns the expected element, you can immediately click on it:

 wait.until(ExpectedConditions.elementToBeClickable(webSite.mainPage().PlusInsideSection)).click(); 

Secondly, it is better to add the wait inside the attributes of your webSite.mainPage() object, rather than override the click() method. That is, as webSite.mainPage().PlusInsideSection as you understand, your webSite.mainPage().PlusInsideSection returns something like driver.find_element(...) , so replace it with wait.until(ExpectedConditions.elementToBeClickable(By(...)))