首页 > 解决方案 > 我正在尝试单击 selenium java 中日期选择器上的下一个按钮,但它在第一次单击后停止并给出元素不可交互的异常。请帮忙

问题描述

    public boolean dateCheck(String doctorName,String dateAppointment,String Time,String symptom) throws Exception
       {           
            driver.findElement(By.xpath("//span[contains(text(),'Schedule Appointment')]")).click();
             driver.findElement(By.xpath("//input[@value='Create new appointment']")).click();
         
    driver.findElement(By.xpath("//h4[contains(text(),'"+doctorName+"')]/ancestor::ul/"
                    + "following-sibling::button[contains(text(),'Book Appointment')]")).click();
         
         calendarFrame=driver.findElement(By.xpath("//iframe[@id='myframe']"));
         driver.switchTo().frame(calendarFrame);         
         driver.findElement(By.xpath("//input[@id='datepicker']")).click();
           
           
           DateTimeFormatter dateformat = DateTimeFormatter.ofPattern("MM/dd/yyyy");
           LocalDate currentDate = LocalDate.parse(dateAppointment,dateformat);    
           int appoint_dt = currentDate.getDayOfMonth();
           int appoint_mth = currentDate.getMonthValue();
           System.out.println("month number give:"+appoint_mth);
           int appoint_yr = currentDate.getYear();
          
          
           SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
           Date currentDate1 = new Date();
           Date todayDate = sdf.parse(dateAppointment);
           System.out.println("today date is :"+currentDate1);
           System.out.println("given date:"+todayDate);
          
           Month month_name = Month.of(appoint_mth);
           System.out.println("given month :"+month_name);
    
    
         monthTitle = driver.findElement(By.xpath("//span[@class='ui-datepicker-month']")).getText();
         year = driver.findElement(By.xpath("//span[@class='ui-datepicker-year']")).getText();       
         

        Month name = Month.valueOf(monthTitle.toUpperCase());
        
         System.out.println("month from calendar:"+ name);
         
         String cal_string = name.toString();
         String given_string = month_name.toString();
     
         while(!cal_string.equalsIgnoreCase(given_string))
         {
                System.out.println("month and year are not  equal");
                System.out.println("months not equal");
                System.out.println("month from calendar:"+ name);
                System.out.println("given month :"+month_name);
                //wait=new WebDriverWait(driver,20);
                //driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/a[2]/span")).click();
                //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='ui-icon ui-icon-circle-triangle-e']"))).click();
                driver.findElement(By.xpath("//span[@class='ui-icon ui-icon-circle-triangle-e']")).click();
                monthTitle = driver.findElement(By.xpath("//span[@class='ui-datepicker-month']")).getText();
                name = Month.valueOf(monthTitle.toUpperCase());
                cal_string = name.toString();
                //given_string = month_name.toString();
                break;
             }
             
         driver.findElement(By.xpath("//div[@id='ui-datepicker-div']/table/tbody/tr/td/child::a[contains(text(),'"+appoint_dt+"')]")).click();
                                                                 
         Thread.sleep(2000);
        
         while(!year.equalsIgnoreCase(Integer.toString(appoint_yr)))
         {
             //driver.findElement(By.xpath("//span[@class='ui-icon ui-icon-circle-triangle-e']")).click();
             driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/a[2]/span")).click();
             year = driver.findElement(By.xpath("//span[@class='ui-datepicker-year']")).getText();
             break;
         }
         
         driver.findElement(By.xpath("//div[@id='ui-datepicker-div']/table/tbody/tr/td/child::a[contains(text(),'"+appoint_dt+"')]")).click();      
         
         time_dropDown = driver.findElement(By.xpath("//select[@name='time']"));
         s = new Select(time_dropDown);
         
         List<WebElement> timeOptions = s.getOptions();
         for (WebElement t : timeOptions) {      
             if(t.getAttribute("value").equalsIgnoreCase(Time))
             {
                 s.selectByValue(Time);
             }      
          }
         Thread.sleep(2000);     
         driver.findElement(By.xpath("//button[@id='ChangeHeatName']")).click();                 
         driver.findElement(By.xpath("//textarea[@name='sym']")).sendKeys(symptom);      
         if(symptom.isEmpty())
         {
             System.out.println("Please provide your symptoms");
         }          
         driver.findElement(By.xpath("//input[@value='Submit']")).click();
         return true;
 }        

标签: javaseleniumdatepickernextclicking

解决方案


推荐阅读