有一个按钮。单击此按钮时,会出现一个包含两个选项的下拉菜单。如何在java中使用selenium验证此场景。
<div class="hpDropDownButton">
<button class="button ng-binding">Holidays Operation</button>
<ul>
<li>
<a class="ng-binding" ng-click="uploadHolidays()">Upload Holidays</a>
</li>
<li>
<a class="ng-binding" ng-click="deleteHolidays()">Delete Holidays</a>
</li>
</ul>
答案 0 :(得分:0)
点击按钮
现在: -
Boolean dropdownPresent = driver.findElement("YOUR LOCATOR OF DROPDOWN").isDisplayed();
if(dropdownPresent==true)
{
System.out.println("Dropdown is appearing");
}
else{
System.out.println("Dropdown is not appearing");
}
希望它会对你有所帮助:)。
答案 1 :(得分:0)
您要求验证整个方案。您需要先了解Selenium-WebDriver
是什么。有关详细说明,请参阅this教程。
但是,您可以按照以下代码
WebDriver driver = new FirefoxDriver();
String appUrl = "your url";
driver.get(appUrl);
// maximize the browser window
driver.manage().window().maximize();
// upto code from your button
WebElement button_element = driver.findElement(button_locator);
button_element.click();
// to verify a drop down menu having two option appears
boolean flag = isPresent(dropdown_locator);
if (flag) {
// code bases on dropdown displayed
}
else {
// code bases on dropdown not displayed
}
验证元素是否存在使用此方法
public boolean isPresent(String locator) {
return findElements(locator).size() > 0 ? true : false;
}
答案 2 :(得分:0)
DropdownFieldName = driver.findElement(by.xpath(//button[@class='button ng-binding'])).click();
drptotalCount = driver.findElements(by.xpath(//a[@class='button ng-binding']));
您可以从以下代码中获取参考:
checkDropDownValues(String DropdownFieldName, String values){
driver.findElement(By.xath(DropdownFieldName)).click();
WebElement drptotalCount = driver.findElements(by.xpath(//a[@class='button ng-binding']));
int numberOfDropDown = drptotalCount.size();
List<String> allDropDownValues = Arrays.asList(values.split("#"));
for (int colCount = 1; colCount <= numberOfDropDown; colCount++) {
boolean flag = false;
Actualvalue = driver.findElement(By.xpath(drptotalCount + "[.=" + allDropDownValues.get(colCount) +"]"])).getText();
String expectedValues = allDropDownValues.get(colCount);
if(expectedValues.equalIgnoreCase(Actualvalue))
{
flag = true;
}
Assert.assertTrue("Column values doesn't match", flag);
}
}
答案 3 :(得分:0)
等待使用WebDriverWait显示下拉“div.hpDropDownButton”:
WebElement myDynamicDropDown =(new WebDriverWait(driver,10))。until(ExpectedConditions.presenceOfElementLocated(By.CssSelector(“div.myDynamicDropDown”)))
继续..