gpt4 book ai didi

java - 基于用户输入的下拉菜单

转载 作者:行者123 更新时间:2023-12-02 02:31:34 25 4
gpt4 key购买 nike

大家可以帮我找到以下案例的解决方案:

我必须输入用户名的几个字母(实际上输入了整个用户名),然后单击它进行选择。它看起来如我在下面添加的屏幕截图。

这是它在页面上的样子:

Added part
<div class="show-temp">
<div class="medium-12 column">
<div id="suggestionBox" class="search-input">
<label for="viewUser">Search user names</label>

<input type="text" autocomplete="off" id="viewUser" onkeydown="javascript: if(event.keyCode == 13 ){ userStats.HideContent();userStats.ApplyFilters(this); return false;}" placeholder="Search user names..">

我尝试使用此代码:

Select dropdown2 = new Select(driver.findElement(By.xpath("//*[@id=\"viewUser\"]")));
dropdown2.selectByVisibleText("Zoran21");
Thread.sleep(2000);

我得到了这个错误:

Element should have been "select" but was "input"

请协助并提前致谢 enter image description here

enter image description here

最佳答案

选择类仅适用于 <select>标签,它不适用于其他标签,例如( Input,div )。如果您想使用 DropDown 首先检查 DoM ,它是如何构建的。如果它包含 <select>标记然后使用 Select Class否则请遵循以下方法。

该错误向您表明,DropDown Build With <Input>标记为使您无法使用选择类别来选择选项

使用以下方法可能会对您有所帮助。

String searchUserXpath ="....";
String optionXpath ="----"
driver.findElement(By.xpath(searchUserXpath )).sendKeys(entersearchOptionValue totally /partially );
//for example option value is HYderabad ,you HYd Then takes xpath of
// HyderabaOPtion...
driver.findElement(By.xpath(optionXpath )).click();

关于java - 基于用户输入的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47013809/

25 4 0