【发布时间】:2018-04-11 10:28:55
【问题描述】:
我有以下 Inspected element Id 用于 UI 屏幕中包含几个字段的下拉菜单。
下拉值:
- 列表项1
- 列表项2
- 列表项3
检查的元素 ID:
<select id="form1:PartialSysAdminKey_adminContractIdField" name="form1:PartialSysAdminKey_adminContractIdField" class="selectOneMenu" size="1">
在某些情况下,下拉列表将不包含任何值。
我需要显示一个 sysout 日志,只有当这个下拉列表有至少一个值时。
有人可以建议我如何将其纳入我的 Selenium 测试吗?
目前,我有以下代码来检查服务器是否已启动并测试登录。
package testPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class TestClass {
public static void main(String[] args) {
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
System.setProperty("webdriver.chrome.driver", "D:\\Softwares\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://bigdata/steward.jsp");
if (driver.getTitle().equalsIgnoreCase("Login")) {
serverStatus = "UP";
} else {
serverStatus = "DOWN";
}
System.out.println("Server is " + serverStatus + ".");
if (serverStatus.equalsIgnoreCase("UP")) {
driver.findElement(By.id("username")).sendKeys("username");
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("login")).click();
String newUrl = driver.getCurrentUrl();
if (newUrl.equalsIgnoreCase("https://bigdata/error.jsp")) {
System.out.println("Incorrect username/password.");
} else {
System.out.println("Logged in successfully.");
}
} else {
System.out.println("Login could not be done.");
}
driver.quit();
}
}
【问题讨论】:
-
这个场景中dropDown在哪里使用?
-
我还没用过。我不知道如何使用它,因为我是 Selenium 的新手。
-
好的,为此分享相关的 HTML。
-
能否请您发布完整的下拉html代码
-
相关HTML?没能得到你。你的意思是我正在测试的整个页面的 HTML?
标签: java selenium selenium-webdriver webdriver selenium-chromedriver