在尝试将文本输入到表单中时,Webdriver出现问题。表单中有我无法摆脱的javascript验证。默认情况下,它会启用一条错误消息,只有在检测到有效输入时才会删除该消息(例如,如果您输入爱尔兰并按TAB或单击away)。
尝试使用selenium中的key.TAB,但不起作用。代码如下:
await driver.wait(until.elementLocated(By.className('combi-select__input')), 15000);
const sets = await driver.findElement(By.className('combi-select__input'));
await sets.sendKeys("IRELAND");现在,当我检查html输出时,表单是空的,我仍然得到错误。我首先尝试了一下click()。
另一方面,这是可行的:
await driver.wait(until.elementLocated(By.className('combi-select__input')), 15000);
const sets = await driver.findElement(By.className('combi-select__input'));
await driver.executeScript("arguments[0].setAttribute('value','IRELAND');", sets);这样做的问题是javascript验证仍然保留错误,因此表单无法提交。
如果有人能帮上忙,那就太棒了。
发布于 2021-09-29 18:27:38
尝试使用JavascriptExecutor
JavascriptExecutor jse = ((JavascriptExecutor)driver);
WebElement email = driver.findElement(By.id("useremail"));
jse.executeScript("arguments[0].value='-----your input----';", email);https://stackoverflow.com/questions/69380867
复制相似问题