提问人:Anit 提问时间:11/6/2023 最后编辑:Anit 更新时间:11/6/2023 访问量:15
如何使用带有 node.js 的 selenium webdriver 自动响应日期和时间
How to automate react date and time using selenium webdriver with node.js
问:
我试图输入值来反应日期(与 https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_date 完全相同的日历)和时间(与 https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_time 完全相同的时间)
var dateInput = await this.driver.findElement(By.xpath(addIncidentDateObject.incidentDate));
await this.driver.wait(until.elementIsVisible(dateInput));
await this.driver.executeScript('arguments[0].focus();', dateInput);
await this.driver.sleep(2000);
await this.driver.executeScript("arguments[0].setAttribute('autocomplete', 'off');", dateInput);
await this.driver.executeScript("arguments[0].setAttribute('autocorrect', 'off');", dateInput);
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('input', { bubbles: true }));", dateInput);
await this.driver.executeScript("dateInput.setAttribute('value', 'Nov 01, 2023')", "");
await this.driver.sleep(2000);
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('change'));", dateInput);
var dateInput2 = await this.driver.findElement(By.xpath(addIncidentDateObject.incidentDate2));
await this.driver.executeScript('arguments[0].focus();', dateInput2);
await this.driver.executeScript(`arguments[0].setAttribute('value', '2023-11-01')`, dateInput2);
await this.driver.sleep(1000);
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('change'));", dateInput2);
var elmentXpath = await this.driver.findElement(By.xpath("//div[contains(text(),'Title')]/following-sibling::input"));
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('change'));", elmentXpath);
await this.driver.sleep(3000);
这是我的代码。日期 - HTML 代码如果我手动添加日期或时间,则两个输入字段的 value 属性都会自动更新。时间 - HTML 代码上面的代码将值输入到相应的字段,但之后,如果我尝试将任何值输入到页面中的任何其他字段,则清除此值。日期的两个输入字段的 Xpath
我尝试更新两个输入字段的 value 属性。当它成功更新并在 UI 中显示该值时,另一个输入事件会清除此值。
答: 暂无答案
评论