Because these methods should, in general, do the smallest chunk of work possible.
This is particularly true with the page object model. The idea behind that model is that your classes (Custom Keywords) should simply act as an interface between the script and the application. In other words, the methods should allow the script writer to do everything that a manual user could do; no more, and no less.
Having the method just return the value means that you can reuse that method for other things, not just the problem you are trying to solve for right now.
In either case, you’ve got a good Custom Keyword to work with, so if you’re comfortable with it, no need to change it. You may find in the future that you want to use the month/year value for something else, in which case you can refer back to this post, which may make more sense at that time
I am having a problematic time with a datepicker calendar that I am trying to do some automated testing for. I tried using setText on the input field that is holding the dates, but the datepicker calendar overwrites it with the current date for the From field and the next day for the To field.
Here is a screen shot as to what I am referring to.
Does the date picker gets triggered by the Set Text or its appearance is part of the flow you’re trying to test ? When does the date picker overwrites the text ? The moment you’re done setting text or the moment the date picker is triggered ? Is there a rationale for this behavior, it could be the developer’s mistake
@ThanhTo I found a work around to handle it. The input box when you click on it triggers the date picker. My solution was to use JavaScript to set the text for the fields and wait a few seconds for my page to recognize it before continuing on with the test case.
Trying to deal with the calendar, I believe, would have been impossible. Trying to do a setText on the input field wasn’t working because the date picker overwrote my text with the current day and the following day.
This code is working
import org.openqa.selenium.JavascriptExecutor
def driver = DriverFactory.getWebDriver()
((JavascriptExecutor) DriverFactory.getWebDriver()).executeScript(“document.getElementById(‘datetimepicker’).value=‘05/05/2020’”)
Hi @Beo,
By using data-driven I want to pick the date from my CSV file while picking am getting invalid formate how can I handle it could you please help me.
Try to enter the date manually and then use the same format as what was entered. Note the date you are getting from your CSV file will be a String, not a Date, so make sure you have the correct data type variable.
List el = driver.findElements(By.xpath("//a[@class=‘ui-state-default’]"))
for(WebElement e :el) {
if(e.getText().equals(futureDay)) {
e.click()
break;
}