2014-02-25 3 views
3

인쇄 링크를 클릭 한 후 인쇄 등록 정보 대화 상자 (Windows 구성 요소)가 올바르게 열리는 지 확인하는 시나리오가 있습니다. Java에서 Robot 유틸리티 클래스를 인식하여 Escape/Enter와 같은 키보드 이벤트를 에뮬레이션하여 해당 윈도우에서 작동 할 수 있습니다. 인쇄 즉 대화 제목을 확인하거나 대화가 수 확인 것이다 창 대화 상자 또는 뭔가 다른 텍스트를 검색하는 일이 - Selenium WebDriver : 페이지에 인쇄 윈도우 대화 상자가 표시되는지 확인합니다.

우리가 열어 새로운 대화를 확인할 수있는 방법이 인쇄 대화를 존재인가 대화 상자를 인쇄하십시오.

Print Window dialog

+0

Propably 중복 : http://stackoverflow.com/questions/11537103/how-to-handle-print-dialog-in-selenium – Spindizzy

+1

@Spindizzy이 질문은 인쇄 창 대화 상자 처리의 다른 측면을 해결합니다. 여기서 나는 새 창이 인쇄 윈도우를 열었 음을 확인하기 위해 뭔가를 원한다. (윈도우 제목이나 인쇄 대화 상자의 일부 요소를 확인할 수있다.) http://stackoverflow.com/questions/11537103/how-to-handle-print-dialog-in-selenium에서는 대화를 처리하는 방법을 설명하고 내 목적을 달성하지 못합니다! –

답변

1

인쇄 대화 상자가 (아직) 처리 할 수 ​​셀레늄 운영 체제에서 온다. 그러므로 당신은 존재를 확인할 수 없습니다. 내가 생각할 수있는 유일한 방법은 java.awt.Robot을 사용하고, VK_ESCAPE를 보내고, 테스트가 계속된다고 주장한다. 당신이 시도 할 수있는 선발로

이 :

 Runnable r = new Runnable() { 

     @Override 
     public void run() { 

      try { 
       Robot r = new Robot(); 
       r.delay(1000); 
       r.keyPress(KeyEvent.VK_ESCAPE); 
       r.keyRelease(KeyEvent.VK_ESCAPE); 
      } catch (Exception ex) { 
       ex.printStackTrace(); 
      } 

     } 
    }; 

    Actions actions = new Actions(getDriver()); 
    actions.sendKeys(Keys.CONTROL).sendKeys("p"); 

    Thread t = new Thread(r); 
    t.start(); 

    actions.perform(); 

    //some stupid asserts that we reached here 
1

당신이 시각적 인 스튜디오와 함께 제공되는 inspect.exe 도구를 사용할 수 있습니다 (나는 당신이 생각 하겠어) 창에서 작업하는 경우 . 대화 상자와 상호 작용하고 드롭 다운 또는 필요한 다른 상호 작용에서 요소를 선택하는 것을 포함하여 원하는 정보를 정확하게 보낼 수 있습니다. 이것은 셀레늄을 사용하여 파일을 저장하려는 경우에도 작동하지만 질문에 대답하기 위해이 파일을 사용하여 해당 창이 실제로 있는지 여부를 감지 할 수도 있습니다. 거기에서 계속하고 싶은 당신의 전화입니다.

//using System.Windows.Automation; 
//using System.Windows.Forms; 

AutomationElement desktop = AutomationElement.RootElement; 
AutomationElement Firefox = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaWindowClass")); 
AutomationElement PrinterComboBox = PrintForm1.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "1139")); 
SelectionPattern selectPrinterComboBox = (SelectionPattern)PrinterComboBox.GetCurrentPattern(SelectionPattern.Pattern); 
AutomationElement ItemInDropdown = PrinterComboBox.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "SelectPrintMethod")); 
SelectionItemPattern ItemInDropdownSelectItem = (SelectionItemPattern)ItemInDropdown.GetCurrentPattern(SelectionItemPattern.Pattern); 
ItemInDropdownSelectItem.Select(); 
AutomationElement OKButton = PrintForm1.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "1")); 
InvokePattern ClickOK = (InvokePattern)OKButton.GetCurrentPattern(InvokePattern.Pattern); 
ClickOK.Invoke(); 
관련 문제