java - 我如何从组合框中检查选定的值
问题描述
我需要确认从组合框中选择的值是否正确并且我有这个代码,但它只是打印选择的值。我想与输入的文本进行比较,如果选择的值正确,则测试应该通过
我在 Java 中使用 Selenium。
Select select = new Select(driver.findElement(By.id ("koopon-produto-select-produto-
especifico-calculos-icms")));
WebElement option = select.getFirstSelectedOption();
String defaultItem = option.getText();
System.out.println(defaultItem);
解决方案
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals;
public class TestJunit1 {
@Test
public void testSelectedCombobox() {
Select select = new Select(driver.findElement(By.id("koopon-produto-
select-produto-especifico-calculos-icms")));
String text = select.getFirstSelectedOption().getText();
assertEquals("expectedText", text);
}
}
推荐阅读
- javascript - Vue Draggable Next - 保存列表的顺序
- hibernate - 带有可选@ManyToOne 的 HQL 多重右连接
- python - PyInstaller 不安装 pandas 之类的模块
- python - 卡在无法为使用 PEP 517 且无法直接安装的密码学构建轮子
- r - 对于大型闪亮应用程序,最初使用 bs_theme() 渲染页面可能会非常慢
- go - 为什么 time.Now() 和 time.Unix() 不同?
- ios - 由于对象列表很大,在 Xcode 中发布归档项目
- optaplanner - 为什么添加硬约束会产生不好的解决方案?
- rabbitmq - RabbitMQ 导出虚拟主机配置
- java - 从构造函数和方法输入数据