2016-09-22 5 views
1

문제는 간단합니다. 자바 스크립트 코드에 의해 생성 된 팝업에서 요소를 클릭해야합니다. 이 페이지는 IE에서만 사용할 수 있으며 개발자 도구가 켜져있을 때는 팝업의 요소를 선택할 수 없습니다. 기본적으로 xpath를 모르지만 팝업을 생성하는 javascript가 있습니다. 이 페이지의 팝업입니다 :자바 스크립트 팝업에서 셀레늄 찾기 요소

Popup on page

그리고이 팝업 생성하는 자바 스크립트 코드 :

function pickDefaultType() { 
    // create popup 
    thePopup = window.createPopup(); 
    var doc = thePopup.document; 
    var body = doc.body; 

    // add stylesheet 
    var oSheet = doc.createStyleSheet(); 
    oSheet.addRule("TD", "cursor: hand; font-family: Verdana, Arial, sans-serif; font-size: " + $('body').css('font-size') + ";"); 
    oSheet.addRule(".TableStyle", "overflow-y: auto; overflow-x: visible;"); 
    oSheet.addRule(".DivStyle", "height: 100%; overflow-y: auto; overflow-x: visible; border: #C1D3E7 1px solid; color: #404040"); 
    oSheet.addRule(".tableHeading", "background-color: #326894; color: white;"); 

    // create scrolling div 
    var theDiv = thePopup.document.createElement("DIV"); 
    theDiv.className = "DivStyle"; 

    body.appendChild(theDiv); 
    theDiv.innerHTML = "<table cellpadding='2' cellspacing='0' width='100%' height='100%'><tr><td id='0'>" + sam.appStrings.defaultDateTypeNone + "</td><tr><tr><td id='1'>" + sam.appStrings.defaultDateTypeCurrent + "</td><tr><tr><td id='2'>" + sam.appStrings.defaultDateTypeOffset + "</td><tr><tr><td id='3'>" + sam.appStrings.defaultDateTypeFixed + "</td><tr></table>"; 
    var theTable = theDiv.firstChild; 
    theTable.className = "TableStyle"; 
    theTable.style.display = ""; 
    theTable.onclick = selectDefaultType; 
    theTable.onmouseover = mouseOver; 
    theTable.onmouseout = mouseOut; 

    // deterine size to show the popup 
    thePopup.show(10, 10, 10, 10, typeSpan); 
    var tableWidth = theTable.offsetWidth + 18; 
    var tableHeight = theTable.offsetHeight + 2; 

    thePopup.show(0, typeSpan.clientHeight + 2, tableWidth, tableHeight, typeSpan); 
} 

내가 XPath와 ID로 요소 "없음"을 찾는 시도를, 내가 사용 기다려라. 예. 요소를 찾을 수 없습니다

Alert promptAlert = webDriver.switchTo().alert(); 
    String alertText = promptAlert.getText(); 
    System.out.println("Alert text is " + alertText); 

:

WebDriverWait wait = new WebDriverWait(webDriver, 3); 
WebElement elem = wait.until(ExpectedConditions.elementToBeClickable(By.id("0"))); 

는 또한 셀레늄의 경고 클래스를 시도했다. 경고가 표시되지 않습니다.

팝업이 프레임에있는 경우 전환 할 이름을 어떻게 찾을 수 있습니까?

Selenium을 사용하여 드롭 다운을 성공적으로 열었습니다. 클릭하면 해당 요소를 찾을 수 없습니다.

미리 감사드립니다.

+0

개발자가 .htc 파일을 사용하여 해당 팝업을 렌더링한다고 들었습니다. 그러면이 팝업에서 요소에 액세스 할 수 있습니까? –

답변

0

때때로 webDriver를 사용하여 팝업에서 요소에 액세스 할 수 없습니다.이 경우 JavascriptExecutor를 사용하여 해당 요소를 찾을 수 있습니다. 그것은 당신이 요소의 "ID"를 알고있는 것 같습니다, 요소에 대한 액세스 권한을 얻으려면 아래 코드를 시도하십시오.

WebElement ele =(WebElement) ((JavascriptExecutor)driver).executeScript("return document.getElementById("yourElementId")); 
+0

나는 이것을 시도했다 : WebElement ele = (WebElement) ((JavascriptExecutor) webDriver) .executeScript ("return document.getElementById ('1')"); ele.click(); 클릭시 NullPointerException이 발생합니다. –

+0

먼저 경고를 표시 한 다음 시도하십시오. –

+0

iframe의 존재를 확인하려면 다음 코드를 사용할 수 있습니다. List iframes = driver.findelements (by.tagname ("iframe" ')); iframe.size()와 같은 목록의 크기()를 확인하여 iFrame의 존재를 확인하십시오. –

관련 문제