JavascriptExecutor 在 Selenium 中无法正常工作。

huangapple go评论133阅读模式
英文:

JavascriptExecutor doesn't work properly with Selenium

问题

以下是翻译好的部分:

  1. private void inputWorkDescription(WebDriver driver, int rawNumber) throws IOException, GeneralSecurityException {
  2. if (!getWorkDescriptionFromSheets(rawNumber).isEmpty()) {
  3. WebDriverWait wait = new WebDriverWait(driver, WAITING_PERIOD);
  4. WebElement workDescription = wait.until(ExpectedConditions.visibilityOfElementLocated(
  5. By.cssSelector("span.placeholder-decoration.ProseMirror-widget span")));
  6. JavascriptExecutor executor = (JavascriptExecutor) driver;
  7. executor.executeScript("arguments[0].click();", workDescription); // ---WORKS
  8. executor.executeScript("arguments[0].value='123456';", workDescription); // --- DOESN'T WORK
  9. executor.executeScript("arguments[0].setAttribute('value', '"
  10. + getWorkDescriptionFromSheets(rawNumber) + "');", workDescription); // --- DOESN'T WORK
  11. }
  12. }

很遗憾,它不能正常工作。我只看到click命令被执行,但没有文字输入。
我尝试了不同的文本输入选项,但都不起作用。

英文:

I use JavascriptExecutor to input the text. My code snippet is as follows

  1. private void inputWorkDescription(WebDriver driver, int rawNumber) throws IOException, GeneralSecurityException {
  2. if (!getWorkDescriptionFromSheets(rawNumber).isEmpty()) {
  3. WebDriverWait wait = new WebDriverWait(driver, WAITING_PERIOD);
  4. WebElement workDescription = wait.until(ExpectedConditions.visibilityOfElementLocated(
  5. By.cssSelector("span.placeholder-decoration.ProseMirror-widget span")));
  6. JavascriptExecutor executor = (JavascriptExecutor) driver;
  7. executor.executeScript("arguments[0].click();", workDescription); // ---WORKS
  8. executor.executeScript("arguments[0].value='123456';", workDescription); // --- DOESN'T WORK
  9. executor.executeScript("arguments[0].setAttribute('value', '"
  10. + getWorkDescriptionFromSheets(rawNumber) + "');", workDescription); // --- DOESN'T WORK
  11. }
  12. }

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 标识符。

对于我的问题,答案在下面的截图中:

JavascriptExecutor 在 Selenium 中无法正常工作。

英文:

I used wrong css identifier.

The answer on my question is on screenshot below

JavascriptExecutor 在 Selenium 中无法正常工作。

huangapple
  • 本文由 发表于 2020年10月16日 03:14:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64378311.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定