0

enter image description hereI want to automate that starting date and end date but in DOM I can't find a Table tag for date picker so I don't know how to locate the field.

The tag is

<input class="inputvd" type="date" name="starting date" value="2023-08-24">

2 Answers 2

2

It's possible - and often done - to have a webpage render something that looks like a table but doesn't use a table tag.

What you want is to identify the field that you're looking for.

In your case it isn't too difficult: you have an input element with a name that ought to be unique in the page.

So, you can locate the starting date field with:

WebElement startDate = driver.findElement(ByName("starting date"));

End date would be similar.

Since both are input elements, all you have to do to set the dates is to call sendKeys():

startDate.sendKeys("2023-03-01");

You don't actually need to simulate clicking into the calendar widget unless you have to validate that you can click on specific dates.

As a general rule, when you are automating user interface interactions, look for the simplest way to get the results you need. Sometimes it's best to step back and think about what you are trying to do before you dive in and try to code it.

It's always helpful to work through a few courses on the language you are using to code your tests - the better you are with the language, the better your automation code will be.

1
0

In test automation services we can achieve this multiple way like using action class and by updating the value in the attribute. It all depend how developer implemented the date picker. Some simple way are as follow.

  1. Update the value of attribute driver.findElement(By.xpath("//input[@class,'inoutvd']'])).setAttribute("value", "your value")
  2. Using java script executer if above method is not working. WebElement element = driver.findElement(By.xpath("//input[@class,'inoutvd']")); // you can use any locator JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("arguments[0].value='updated date value';", element);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.