[英]How to verify the dropdown options matching with the UI options in selenium WebDriver using Java?
I have written the code how to read the options from the property file. 我已经编写了如何从属性文件读取选项的代码。 But I don't know how to verify the same value is there in the UI drop down.
但是我不知道如何在UI下拉菜单中验证相同的值。
Please anyone help me the same code: 请任何人帮助我相同的代码:
@Test()
public void Filterselection_1() throws Exception{
try {
FileInputStream fstream = new FileInputStream("C:/FilterSection/visualization.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
Try the code given below 试试下面给出的代码
If the List of Values is not empty ie it contains values that are not present in the property file, print message stating the same. 如果“值列表”不为空,即它包含属性文件中不存在的值,请打印说明相同的消息。
@Test() public void Filterselection_1() throws Exception{ try { //Find the drop down Select select = new Select(DropDownElement); //Get all options to a List List<WebElement> options = select.getOptions(); //Iterate through the list and create a list of String containing all the values List<String> valueList = new ArrayList<String>(); for (Webelement option : options) { valueList.add(option.getText()); } FileInputStream fstream = new FileInputStream("C:/FilterSection/visualization.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { //find whether the value is present in the value list if (valueList.contains(strLine)) { valueList.remove(strLine); } else { System.out.println(strLine + "not found in the drop down"); } } //Close the input stream in.close(); //check if valueList is empty (it will be empty if all the values //in the dropdown are present in the property file) if (!valueList.isEmpty()) { Ststem.out.println("The following values present in the dropdown are not present in the property file : "); for (String s : valueList) { System.out.prinyln(s); } } }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); }
} }
Let me know if this helps you. 让我知道这是否对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.