简体   繁体   English

如何使用Java验证与Selenium WebDriver中的UI选项匹配的下拉选项?

[英]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 试试下面给出的代码

  1. We Find the drop down element 我们找到下拉元素
  2. Get all the options to a List 获取所有选项到列表
  3. Create a List of values from the options list 从选项列表中创建值列表
  4. Read the property file line by line 逐行读取属性文件
  5. Check whether each line is present in the List of values 检查值列表中是否存在每一行
  6. If present, remove that value from the List of Values 如果存在,请从值列表中删除该值
  7. If not present, print value not present 如果不存在,则打印值不存在
  8. 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.

相关问题 如何比较下拉选项与Selenium WebDriver中的UI选项是否匹配? - How to compare the drop down options is matching with the UI options in Selenium WebDriver? 如何使用 Java 检查下拉列表中的选项在 Selenium Webdriver 中显示两次 - How to check that the options in dropdown are displayed twice in Selenium Webdriver using Java 如何使用Java和Webdriver验证下拉菜单中的所有可用选项 - How do I verify all the available options in a dropdown using Java and Webdriver 使用Java和Selenium,如何在下拉菜单中选择所有选项? - Using Java and Selenium, how can I select all the options in a dropdown? 如何使用Java验证Selenium WebDriver中的tooltipText - How to verify tooltipText in Selenium WebDriver using Java 在Selenium Webdriver中的引导程序下拉菜单中选择选项 - Selecting options in a bootstrap dropdown menu in selenium Webdriver 如何使用 Selenium WebDriver java 从下拉列表中获取所有选项 - How to get all the options from drop down using Selenium WebDriver java 如何使用Java计算Selenium WebDriver中选择下拉框中的选项数量? - How to count the number of options in a select drop down box in Selenium WebDriver using Java? 在Java + Selenium WebDriver中提取选择的选项 - Extract the options of a select in Java + Selenium WebDriver 如何使用Selenium WebDriver和Java通过匹配文本模式从下拉列表中选择选项 - How to select an option from dropdown list by matching text pattern using selenium webdriver and java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM