Need to select from dropdown. If selected 'Yes', need to fill certain text field and if selected 'no' then other text field need to be completed using selenium with java binding.

        WebElement JointApplication = driver.findElement(By.id("-1-1-joint_life"));     
        Select Joint = new Select(JointApplication);

        Joint.selectByVisibleText("Yes");

        List<WebElement>options = Joint.getOptions();
        int aaa = options.size();

        System.out.println(aaa);
        for(int i = 0; i < aaa; i++)
        {
        if(options.get(i).getText().equalsIgnoreCase("Yes"))
        {
            // if we select yes for Joint Application
            Thread.sleep(2000);
            WebElement Title=driver.findElement(By.id("dd-2-1-title1"));
            Select Tit=new Select(Title);
            Tit.selectByVisibleText("Mr");
         } else {
        Thread.sleep(2000);
        WebElement Title=driver.findElement(By.id("dd-2-1-title1"));
        Select Tit=new Select(Title);
        Tit.selectByVisibleText("Mr"); }

enter image description here

enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.