英文:
JavascriptExecutor doesn't work properly with Selenium
问题
以下是翻译好的部分:
private void inputWorkDescription(WebDriver driver, int rawNumber) throws IOException, GeneralSecurityException {
if (!getWorkDescriptionFromSheets(rawNumber).isEmpty()) {
WebDriverWait wait = new WebDriverWait(driver, WAITING_PERIOD);
WebElement workDescription = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("span.placeholder-decoration.ProseMirror-widget span")));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", workDescription); // ---WORKS
executor.executeScript("arguments[0].value='123456';", workDescription); // --- DOESN'T WORK
executor.executeScript("arguments[0].setAttribute('value', '"
+ getWorkDescriptionFromSheets(rawNumber) + "');", workDescription); // --- DOESN'T WORK
}
}
很遗憾,它不能正常工作。我只看到click
命令被执行,但没有文字输入。
我尝试了不同的文本输入选项,但都不起作用。
英文:
I use JavascriptExecutor
to input the text. My code snippet is as follows
private void inputWorkDescription(WebDriver driver, int rawNumber) throws IOException, GeneralSecurityException {
if (!getWorkDescriptionFromSheets(rawNumber).isEmpty()) {
WebDriverWait wait = new WebDriverWait(driver, WAITING_PERIOD);
WebElement workDescription = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("span.placeholder-decoration.ProseMirror-widget span")));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", workDescription); // ---WORKS
executor.executeScript("arguments[0].value='123456';", workDescription); // --- DOESN'T WORK
executor.executeScript("arguments[0].setAttribute('value', '"
+ getWorkDescriptionFromSheets(rawNumber) + "');", workDescription); // --- DOESN'T WORK
}
}
Unfortunately, it doesn't work properly. I just see that click
command performed but no text input.
I tried different options for text input but it doesn't work.
答案1
得分: 0
我使用了错误的 CSS 标识符。
对于我的问题,答案在下面的截图中:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论