Selenium webdriver 如何使用Selenium在组合框上键入

Selenium webdriver 如何使用Selenium在组合框上键入,selenium-webdriver,jbehave,Selenium Webdriver,Jbehave,当我尝试使用selenium在组合框上键入时,我发现了一些困难。实际上,组合框使用javascript和ajax加载数据。当用户单击按钮下拉列表时,组合框将加载数据。实际上,我发现了一些困难,因为我无法使用函数selectByValue()或selectByVisibleText()。代码如下: <table id="isc_U5" class="OBFormFieldSelectControl" cellspacing="0" cellpadding="0" style="cursor:

当我尝试使用selenium在组合框上键入时,我发现了一些困难。实际上,组合框使用javascript和ajax加载数据。当用户单击按钮下拉列表时,组合框将加载数据。实际上,我发现了一些困难,因为我无法使用函数
selectByValue()
selectByVisibleText()
。代码如下:

<table id="isc_U5" class="OBFormFieldSelectControl" cellspacing="0" cellpadding="0" style="cursor:default;WIDTH:307px;" $9a="$9f" $89="isc_OBFKComboItem_8" role="presentation">
<tbody>
<tr>
<td style="white-space:nowrap;">
<input id="isc_U3" class="OBFormFieldSelectInputRequired" type="TEXT" tabindex="4078" style="WIDTH:281px;HEIGHT:17px;-moz-user-focus:normal;" autocomplete="OFF" onselect="isc_OBFKComboItem_8.$1162()" oninput="isc_OBFKComboItem_8._handleInput()" spellcheck="true" $9a="$9b" $89="isc_OBFKComboItem_8" handlenativeevents="false" name="transactionDocument"/>
</td>
<td id="isc_U7" class="OBFormFieldSelectPickerIcon" style="font-size:21px;">
</tr>
</tbody>
</table>

请尝试下面的c代码

选项1 使用SendKeys直接发送ComboBox值,因为它只是一个输入元素

comboBoxElement.SendKeys("ComboBox value to select");
选项2 键入要选择的值的前几个字符

comboBoxElement.SendKeys("TE");

这将允许您的应用程序显示UL和LI标签,其中LI值以TE开头。。现在找到UL元素并找到它的子LI元素。迭代每个LI元素并执行。在迭代过程中找到所需值时单击。

尝试以下代码。我用过JAVA

  • 使用普通发送键:

    driver.findElement(By.cssSelector("input.OBFormFieldSelectInputRequired").sendKeys("Beginning letters of the word you want");
    
  • 使用
    findElements

    List<WebElement> elements = driver.findElements(By.cssSelector("list items cssSelector"));
            for (WebElement element : elements) {
                if (element.getText().equalsIgnoreCase("Enter the text you want")) {
                    element.click();
                     break;
                }
             }
    

  • 您的代码在哪里?我已经使用了选项1和选项2,但它不起作用。也许3号选项是目前最好的答案。我会尝试使用它谢谢@selvaI已经在使用sendKeys功能,但它不起作用。我使用java代码可能会将其更改为C#这需要很多努力
    List<WebElement> elements = driver.findElements(By.cssSelector("list items cssSelector"));
            for (WebElement element : elements) {
                if (element.getText().equalsIgnoreCase("Enter the text you want")) {
                    element.click();
                     break;
                }
             }
    
    List<WebElement> elements = driver.findElements(By.cssSelector("list items cssSelector"));
    Robot bot = new Robot();
    bot.setAutoDelay(1);
    
    for (WebElement element : elements) {
             bot.keyPress(KeyEvent.VK_DOWN);
             bot.keyRelease(KeyEvent.VK_DOWN);
             if (element.getText().equalsIgnoreCase("Enter the text you want")) {
                 bot.keyPress(KeyEvent.VK_ENTER);
                 bot.keyRelease(KeyEvent.VK_ENTER);
                 break;
             }
    }