简体   繁体   English

下拉缺少最终点击

[英]Dropdown missing final click

Guys could someone please assist me to finish following: I need to open dropdown and choose option.伙计们,有人可以帮助我完成以下操作:我需要打开下拉菜单并选择选项。 My code is:我的代码是:

WebElement sorter = driver.findElement(By.cssSelector(".column.medium-12 .row"));
    sorter.click();
    Actions keyDown = new Actions(driver);
    keyDown.sendKeys(Keys.chord(Keys.DOWN)).perform();

I use following since there is no other way to open dropdown.我使用以下,因为没有其他方法可以打开下拉菜单。 After above code finishes, it looks like as on screenshot (stuck on first chosen option without confirmation).上面的代码完成后,它看起来像屏幕截图(在没有确认的情况下卡在第一个选择的选项上)。 I am actually missing confirmation click but could not find solution.我实际上缺少确认点击但找不到解决方案。 Please assist, thank you in advance.请帮忙,先谢谢了。

在此处输入图片说明

I'm guessing that the drowdown is just a normal <select> html element.我猜测下拉只是一个普通的<select> html 元素。

If that's the case, then you can iterate over the <option> elements of the drowdown and select the first.如果是这种情况,那么您可以遍历下拉<option><option>元素并选择第一个。

WebElement sorter = driver.findElement(By.cssSelector(".column.medium-12 .row"));
sorter.click();
List<WebElement> elements = sorter.findElements(By.tagName("option");
WebElement option = elements.get(0);
option.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM