输入框测试

// 根据inspect.exe确定name
WebElement element = this.driver.findElementByName("accessiableName_LineEdit");
// 模拟鼠标点击,聚焦
element.click();
// 简单的模拟输入
element.sendKeys("test");
// 获取输入后的值
String content = element.getText();
// 与期望值进行比较
Assert.assertEquals("test", content);
下拉框测试
// 根据inspect.exe确定name
WebElement element = this.driver.findElementByName("accessiableName_ComboBox Down");
// 模拟鼠标点击,弹出下拉选项
element.click();
// 确定需要选择的选项(qt软件中,下拉框的选项的name与其显示的值一致)
String selectValue = "贲门";
// 通过findElement,树形结构向下检索需要定位的element
WebElement element1 = element.findElement(By.name("AccessiableName_QComboBoxListView AccessiableName_QComboBoxListView")).findElement(By.name(selectValue));
// 模拟鼠标选择点击事件
element1.click();
// 获取输入后的值
String content = element.getText();
// 与期望值进行比较
Assert.assertEquals(selectValue, content);
弹窗测试
// 根据inspect.exe确定name
WebElement element = this.driver.findElementByName("accessiableName_PushButton");
// 模式鼠标点击按钮,弹出弹框
element.click();
// 获取当前窗体的句柄,并获得最顶层messageBox name
String messageBox = this.driver.getWindowHandles().toArray()[0].toString();
// 定位到顶层messageBox
this.driver.switchTo().window(messageBox);
// 根据inspect.exe确定弹窗按钮
WebElement element1 = this.driver.findElementByName("OK Enter");
// 模拟点击弹窗上的按钮
element1.click();
单选测试
// 根据inspect.exe确定name
WebElement element = this.driver.findElementByName("accessiableName_RadioButton");
// 模拟单选选中
element.click();
// 获取单选选中后的值
String value = element.getAttribute("SelectionItem.IsSelected");
boolean radioValue = "True".equals(value);
Assert.assertEquals(true, radioValue);
// 模拟取消选中
element.click();
value = element.getAttribute("SelectionItem.IsSelected");
boolean radioValue = "True".equals(value);
Assert.assertEquals(false, radioValue);
多选测试
// 根据inspect.exe确定name
WebElement element = this.driver.findElementByName("accessiableName_CheckBox");
// 模拟多选框选中
element.click();
// 获取多选框后的值
String value = element.getAttribute("Toggle.ToggleState");
boolean checkValue = "1".equals(value);
Assert.assertEquals(true, radioValue);
// 模拟取消选中
element.click();
value = element.getAttribute("Toggle.ToggleState");
boolean checkValue = "1".equals(value);
Assert.assertEquals(false, checkValue);
文本框测试
// 根据inspect.exe确定name
WebElement element = this.driver.findElementByName("accessiableName_TextEdit");
// 模拟鼠标定位聚焦
element.click();
// 清空文本框
element.clear();
// element可以做简单的点击、输入操作,比较复杂的操作可以借助Actions对象来完成
Actions actions = new Actions(this.driver);
// 模拟键盘输入值
actions.sendKeys(element, “123”);
// 执行
actions.perform();
// 获取文本框的录入值
String value = element.getText();
// 与期望值进行比较
Assert.assertEquals("123", value);