首页 > 解决方案 > 我无法使用 selenium 将密钥发送到输入元素。也试过用js

问题描述

<div class=" css-0">
<div class="css-zcohbc-singleValue">General</div>
</div>

<div class="css-0">
<div class="" style="display: inline-block;">
<input autocapitalize="none" autocomplete="off" autocorrect="off" id="react-select-3-input" spellcheck="false" tabindex="0" type="text" aria-autocomplete="list" value="" style="box-sizing: content-box; width: 2px; background: 0px center; border: 0px; font-size: inherit; opacity: 1; outline: 0px; padding: 0px; color: inherit;">

<div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 14px; font-family: Roboto, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;">
</div>
</div>
</div>
</div> 

我需要将密钥发送到输入标签。

WebElement elmnt = driver.findElement(By.xpath("//input[@aria-autocomplete='list']"));

尝试使用普通的 Selinium,

elmnt.click();
elmnt.sendKeys("Text");

还尝试用 JS 点击并发送密钥

JavascriptExecutor js= (JavascriptExecutor) driver;
js.executeScripts("arguments[0].click();",elmnt);
elmnt.sendKeys("Text");

任何人都可以建议,我可能会错过什么?

标签: seleniumselenium-webdriver

解决方案


推荐阅读