简体   繁体   中英

How to automate an analog clock with selenium webdriver and Java?

Context: I have to automate the time setting with the following rule: The configured time must be 40 minutes longer than the current time.

Field details: The field is not editable. When I click on the field, I press an analog clock popup and after I manually select the time, then the field starts showing the selected time (rule: I must have chosen 40 minutes more than the current time)

Question: How do I get my automation to take the current time, add 40min and put this value in the field without having to open the popup?

I tried this, but it didn't work: driver.findElement(By.name("dateSend")).sendKeys("22/07/2020-17:28");

ERRO: org.openqa.selenium.ElementNotInteractableException: element not interactable

Below are the images of the code and field:

Imagem do campo: não editável enter image description here

Código do campo enter image description here

Imagem do popup enter image description here

Código do popup enter image description here

Campo 'Disparo' após selecioada a hora: enter image description here

Código do campo com horário enter image description here

ElementNotInteractableException

Its indicate that even though element is present in DOM but currently its not in state to interact. Refer to this SO thread for detail explanation.

Possible Solution

Now coming to your question. Use below code to add 40 minutes into current time:

String updateTime = "";
DateFormat timeFormat = new SimpleDateFormat("HH:mm");
Calendar cal = Calendar.getInstance();
//Adding 40 minute in current time
cal.add(Calendar.MINUTE, 40)

updateTime = timeFormat.format(cal.getTime());

And then you can try to set value in element as:

driver.findElement(By.name("dateSend")).sendKeys("value", updateTime);

OR using javaScript

WebElement element = driver.findElement(By.name("dateSend"));
 JavascriptExecutor jse = (JavascriptExecutor)driver;
 jse.executeScript("arguments[0].value='"+updateTime+"';", element);

Also, from attached image, analog clock has 12 hours mode. Try to set value in both AM and PM mode, and then set SimpleDateFormat according to that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM