How to Automate the fields that are text and drop downs. You are not sure that how may fields will be there



  • The situation is that admin sets the Specified fields for the front end user and it is upon admin to decide how many fields he'll set for the user. One thing is that he can only create 2 types of fields; either Text or Dropdown.

    Also, the user can make that field mandatory. Now the question is how can I automate that using selenium and java. I have to check that either these fields are present or not and if present then which type of it and then I have to check that either it is necessary or nor.

    Here I am attaching an image from DOM. I think that here Divs has been used. Also, one thing possible is there is an option that Specified Meetings fields may be not present. So I have to first check that either these fields are present or not. So the scenario will be like this:

    • Meeting Specifics fields are present or not
    • The field is of type text or Dropdown
    • The field is necessary or not
    • Either the next field exists or not.

    enter image description here

    enter image description here



  • See, i will suggest you that this all is depends on your test cases that what scenarios are they following.

    From my point, suppose that if test case start from that your admin has select some number of input and Select fields then you come to your Meeting Specific page and here you will count the number of all fields present here, it means you already well know that what fields will present here with what numbers, so you just need to check that fields.
    Here may this code help you:

            List<WebElement> element=driver.findElements(By.tagName("select"));
            Assert.assertEquals(element.size(), 2);
            for(WebElement attr:element)
            {
                Assert.assertEquals(attr.getAttribute("required"), "true");
            }
            List<WebElement> element1=driver.findElements(By.tagName("input"));
            Assert.assertEquals(element1.size(), 1);
            for(WebElement attr1:element1)
            {
                Assert.assertEquals(attr1.getAttribute("required"), "true");
            }  
    

    And in second case if as a admin you have not selected any fields then you already know that on Meeting Specific page there will be no fields, then you just need to verify that no input and select are present.
    Here may this code help you-

            List<WebElement> element=driver.findElements(By.tagName("select"));
            Assert.assertEquals(element.isEmpty(), true);
    
            List<WebElement> element1=driver.findElements(By.tagName("input"));
            Assert.assertEquals(element1.isEmpty(), true);
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2