![](/img/trans.png)
[英]How to automate flash with sikuli with selenium webdriver java
[英]How to automate an analog clock with selenium webdriver and Java?
上下文:我必須使用以下規則自動設置時間:配置的時間必須比當前時間長 40 分鍾。
字段詳細信息:該字段不可編輯。 當我點擊該字段時,我按下一個模擬時鍾彈出窗口,然后手動 select 時間,然后該字段開始顯示所選時間(規則:我必須選擇比當前時間多 40 分鍾)
問題:如何讓我的自動化獲取當前時間、添加 40 分鍾並將此值放入字段中而無需打開彈出窗口?
我試過了,但沒有用: driver.findElement(By.name("dateSend")).sendKeys("22/07/2020-17:28");
錯誤:org.openqa.selenium.ElementNotInteractableException:元素不可交互
以下是代碼和字段的圖像:
Imagem do campo: não editável在此處輸入圖像描述
Código do campo在此處輸入圖片描述
Imagem do popup enter image description here
Código do popup enter image description here
Campo 'Disparo' após selecioada a hora:在此處輸入圖片描述
Código do campo com horário在此處輸入圖像描述
ElementNotInteractableException
它表明即使元素存在於 DOM 中,但目前它不在 state 中進行交互。 有關詳細說明,請參閱此SO 線程。
可能的解決方案
現在來回答你的問題。 使用以下代碼將 40 分鍾添加到當前時間:
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());
然后您可以嘗試將元素中的值設置為:
driver.findElement(By.name("dateSend")).sendKeys("value", updateTime);
或使用 javaScript
WebElement element = driver.findElement(By.name("dateSend"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].value='"+updateTime+"';", element);
此外,從附圖中,模擬時鍾具有 12 小時模式。 嘗試在 AM 和 PM 模式下設置值,然后根據該設置SimpleDateFormat
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.