1

I have one dropdown that contains 6 values.

Actual scenario is if you select any value from dropdown then the selected value will appear in next page

for eg: I selected city Mumbai from dropdown, then on next page Mumbai city is selected will appear as text.

I want to verify the selected value is appearing correctly on next page.

4

2 回答 2

0

单击选项

Select select = new Select(driver.findElement(By.xpath("//path_to_drop_down")));
select.deselectAll();
select.selectByVisibleText("Value1");

还有更多方法,您可以选择如何定位元素。我建议给每个人命名并按名称查找元素

断言存在 -

使用类似的东西

public boolean verifyTextInField(String expectedValue, By by) {
    try {
        assertEquals(expectedValue,
                driver.findElement(by).getAttribute("value"));
        System.out.println("Values are equal");
        return true;
    } catch (Error e) {
        verificationErrors.append(e.toString());
        System.out.println("Values are unequal");
        return false;
    }
}
于 2012-08-31T12:19:15.413 回答
0

对于下拉列表中的选择元素,您可以使用 js 执行器:

String cssLocator=....
JavascriptExecutor js = (JavascriptExecutor) driver;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("var x = $(\'"+cssLocator+"\');");
        stringBuilder.append("x.click();");
        js.executeScript(stringBuilder.toString());

然后切换到下拉菜单并切换值:

String dropdownValue=driver.findElement(By.xpath("..."))).getText().trim();//类似的东西然后你可以切换到下一页的文本标签

String labelValue= driver.findElement(By.xpath("..."))).getText().trim();

并比较两个stings:dropdownValue 和labelValue

希望这可以帮助你

于 2012-09-06T15:50:24.477 回答