gpt4 book ai didi

java - 无法点击 'Text' 内的 'dropdown list'

转载 作者:行者123 更新时间:2023-11-29 04:34:36 27 4
gpt4 key购买 nike

  1. 无法点击“下拉列表”中的“文本”
  2. 当向控制台输出信息时,它会列出所有头衔(先生、夫人...)
  3. 我只是无法点击 .Mr 文本,有什么想法吗? (我不想使用发送键)

    public void selectOptionFromDropdownMenu(WebElement dropdown, String textToSearchFor) {
    List<WebElement> options = dropdown.findElements(By.tagName("option"));
    dropdown.click();
    System.out.println(options.size());

    for (int i = 0; i < options.size(); i++) {
    System.out.println("DEVIL!!!" + options.get(i).getText());

    if(options.get(i).getText() == "Mr.") {
    options.get(i).click();
    }
    }

enter image description here

<select id="titlefield" class="form-control ng-pristine ng-untouched ng-invalid ng-invalid-required" name="Salutation" ng-model="PersonalDetails.Salutation" ng-options="salut.id as salut.id for salut in Salutations" ng-required="FlowData.IsGuest" required="required">
<option class="ng-binding" value="">Please select</option>
<option value="0" label="Mr.">Mr.</option>
<option value="1" label="Miss">Miss</option>
<option value="2" label="Mrs.">Mrs.</option>
<option value="3" label="Ms.">Ms.</option>
<option value="4" label="Dr.">Dr.</option>
</select>

最佳答案

public void selectOptionFromDropdownMenu(WebElement dropdown, String textToSearchFor) {
List<WebElement> options = dropdown.findElements(By.tagName("option"));
Select selectDropdown = new Select(dropdown);
//dropdown.click();
System.out.println(options.size());

for (int i = 0; i < options.size(); i++) {
System.out.println("DEVIL!!!" + options.get(i).getText());

if(options.get(i).getText().equals(textToSearchFor)) {
selectDropdown.selectByVisibleText(textToSearchFor);
//options.get(i).click();
}
}

关于java - 无法点击 'Text' 内的 'dropdown list',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42224669/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com