2016-09-27 4 views
0

웹 자동화 테스트 및 Java로 스크립트 작성에 Selenium WebDriver를 사용하고 있습니다.생년월일 Selenium WebDriver에서 날짜 선택기를 선택하는 방법

"데이트 탄생을 선택"할 때까지는 좋은 시작이었습니다. 날짜 선택기에서 날짜, 월 및 연도 값을 선택하는 방법을 알고 싶습니다. 선택할 날짜는 1966 년 12 월 14 일입니다.

주소 : http://radcard-cloud.idatamap.com/login

Photo of the calendar

이 내가하려고 내 마지막 코드입니다. 나는 그것을 마무리하려고 거의 4 일을 보냈다. 도와주세요!

package iDMautomation; 
 
    
 
import org.openqa.selenium.By; 
 
import org.openqa.selenium.Keys; 
 
import org.openqa.selenium.WebDriver; 
 
import org.openqa.selenium.WebElement; 
 
import org.openqa.selenium.chrome.ChromeDriver; 
 
import org.openqa.selenium.support.ui.ExpectedConditions; 
 
import org.openqa.selenium.support.ui.Select; 
 
import org.openqa.selenium.support.ui.WebDriverWait; 
 
import java.util.List; 
 
import org.openqa.selenium.firefox.*; 
 
import java.util.concurrent.*; 
 

 
public class FirstTest { 
 
     
 

 
\t public static void main(String[] args) { 
 
      
 
     //initialize Chrome driver 
 
     System.setProperty("webdriver.chrome.driver", "C:\\Users\\senn\\Desktop\\RadCard Test\\Selenium\\chromedriver_win32\\chromedriver.exe"); 
 
     WebDriver driver = new ChromeDriver(); 
 
     
 
      
 
     //Open gmail 
 
     driver.get("http://radcard-cloud.idatamap.com/"); 
 
     driver.manage().window().maximize(); 
 
      
 
     //driver.findElements(By.xpath(xpathExpression)) 
 
     // Enter userd id 
 
      
 
     driver.findElement(By.className("patient")).click(); 
 
      
 
     //email pedram 
 
     //driver.findElement(By.className("providerNum")).click(); 
 
     WebDriverWait wait = new WebDriverWait(driver, 20);// 1 minute 
 
     wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("email"))); 
 

 
      
 
     driver.findElement(By.id("email")).click(); 
 
     driver.findElement(By.id("email")).sendKeys("[email protected]"); 
 
      
 
     driver.findElement(By.id("PIN")).sendKeys("2281"); 
 
      
 
     driver.findElement(By.id("DOB")).click(); 
 
      
 
     
 
     Select sel1=new Select(driver.findElement(By.cssSelector("DOB")));  
 
     WebElement FirstTest = driver.findElement(By.id("DOB")); 
 
      
 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
 
     driver.findElement(By.className("ui-datepicker-current-day")).click(); 
 
      
 
     Select sel3=new Select(driver.findElement(By.cssSelector("selectDay"))); 
 
      
 
     new Select((WebElement) sel3).selectByVisibleText("14");  
 
      
 
     FirstTest.sendKeys(Keys.ENTER);
모든

+0

당신이 원하는 마십시오과 하나가 그 66 년의 어떤 날짜의 특정 날짜?달력을 사용하여 선택 하시겠습니까? 아니면 그냥 설정 하시겠습니까? – lauda

답변

0

먼저,이 때문에 태그가 올바르지 않을 수 있습니다, 자바, 자바 스크립트되지 것 같습니다.

좋아요, 한 번에 하나씩 해봅시다. 수동으로 어떻게 할 것인지 :

  1. 는 "생년월일"에 대한 입력 필드를 클릭
  2. 월을 선택
    이의 클래스 명을 채우고 볼 수
  3. 가되는 캘린더
  4. 기다립니다 메뉴 및 각 옵션에는 선택할 값과 텍스트가 있습니다.
  5. 연도 선택 (다른 클래스 이름 및 메뉴 옵션으로 3 단계 반복)
    드롭 다운 메뉴에 값이 있으므로 코드가

    driver.findElement(By.className("ui-datepicker-current-day")).click(); 
    
    Select sel3=new Select(driver.findElement(By.cssSelector("selectDay"))); 
    
    new Select((WebElement) sel3).selectByVisibleText("14"); 
    

    를 작동하지 않는 이유 t는 당신은 눈에 보이는 달에서 우려의

몇 가지 날짜를 "클릭"할

  • 를 원하고있을 수 있습니다 년에 정확히 맞 춥니 다 첫 번째 줄은 오늘 날짜를 클릭하려고 시도하는 것입니다. 구체적으로는 14 일이 아닙니다.

    두 번째 줄과 세 번째 줄은 달력 날에 선택하려고하는 것처럼 보이지만, 그렇지 않은 요소에서는 수행 할 수 없습니다. 드롭 다운 선택 남성 유. 클릭 만 할 수 있습니다. 또한, 나는 꽤 cssSelector ("selectDay")가 작동하지 않는다고 확신합니다. Id, classname, tagname 등을 찾고 있다면 cssSelector와 관련된 몇 가지 문제점을 볼 수 있습니다.

    여기에도 세 번째 줄에서 새 선택을 WebElement로 만들고 캐스팅하는 이유는 무엇입니까? 당신은 DOB가 ID

    sel3.selectByVisibleText("14"); 
    

    인가 할 수있을 것인가? 당신은

    driver.findElement(By.id("DOB")).click();; 
    

    그리고 다른

    Select sel1=new Select(driver.findElement(By.cssSelector("DOB"))); 
    
  • 관련 문제