【问题标题】:WebDriver not detecting input textbox, throws ElementNotInteractableException: element not interactableWebDriver 未检测到输入文本框,抛出 ElementNotInteractableException:元素不可交互
【发布时间】:2020-04-21 20:35:45
【问题描述】:

我已经编写了一些代码来将输入发送到文本框,如下所示:

但是在执行过程中,即使显示输入类型是文本框,webdriver 也会返回 ElementNotInteractableException。

我尝试使用以下方式发送输入但不成功,寻求建议,谢谢!:

1)

driver.findElement(By.xpath("//input[@name='bkg_no']")).sendKeys("ABCDE9000333");

2)

String bkg = "ABCDE9000333"
WebElement bkgNo = driver.findElement(By.xpath("//input[@name='bkg_no']"));";
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].value="+bkg+";", bkgNo);

3)

driver.findElement(By.name("bkg_no")).sendKeys("ABCDE9000333");

4)

JavascriptExecutor jse = (JavascriptExecutor)driver;    
jse.executeScript("document.getElementByName('bkg_no').value='PKG900890300'");

【问题讨论】:

  • 你看到这个答案了吗? stackoverflow.com/a/46601444/1230748
  • 我尝试使用您在该帖子中描述的 wait() 方法,它仍然不起作用,我注意到当我使用 excecuteScript() 时,代码运行时没有任何异常但没有输入任何内容进入文本框Code WebElement element=driver.findElement(By.xpath("//input[@name='bkg_no']")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element); executor.executeScript("arguments[0].value='ABCDE90003330';",element);

标签: java selenium xpath css-selectors webdriverwait


【解决方案1】:

要将字符序列发送到<input>,您必须为element_to_be_clickable() 诱导WebDriverWait,您可以使用以下Locator Strategies 之一:

  • cssSelector

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("form[name='form'][onkeydown*='search'] div.wrap_search input.input[name='bkg_no']"))).sendKeys("ABCDE9000333");
    
  • xpath

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//form[@name='form' and contains(@onkeydown, 'search')]//div[contains(@class, 'wrap_search')]//input[@class='input' and @name='bkg_no']"))).sendKeys("ABCDE9000333");
    

【讨论】:

  • 这似乎不起作用,该元素只能通过其相对 xpath //input[@name='bkg_no'] 以某种方式找到。奇怪的是,当我在 chrome 中使用 selenium IDE 插件时,它能够按名称找到输入框,当我播放录音时,它似乎工作成功,不知道为什么:/
猜你喜欢
  • 1970-01-01
  • 2021-08-21
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 2020-09-12
  • 1970-01-01
  • 2021-01-08
  • 2021-03-09
相关资源
最近更新 更多