我写了一些代码将输入发送到文本框,如下所示:
但是,在执行过程中,即使驱动程序显示输入类型是文本框,它也会返回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'");
要将字符序列发送到<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");