1

The problem is simple. I need to click an element in a popup that is generated by javascript code. The page is only available in IE and the elements in the popup cannot be selected when Developers tools is on. Basically I do not know the xpath but I do have the javascript that generates the popup. This is the popup on page:

Popup on page

And this is the javascript code that generates the popup:

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);
}

I have tried locating the element "None" with xpath and id, I used wait as well, e.g.

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

I have also tried the Alert class from Selenium:

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

The element cannot be found. The Alert is not present.

If the popup is in a frame, how do I find out the name of it to switch to it?

Please note that I have successfully opened the dropdown using Selenium, just cannot find the elements on it to click on them.

Thank you in advance!

1
  • I have been told by a developer that .htc files are used to render that popup. Can I access the elements on this popup then? Commented Sep 22, 2016 at 2:51

1 Answer 1

0

Sometimes, we are not able to access element in pop up using webDriver, in that case we can use JavascriptExecutor to find that element. It seems that you know the "Id" of the element, please try below code to get access to the element.

WebElement ele =(WebElement) ((JavascriptExecutor)driver).executeScript("return document.getElementById("yourElementId"));
Sign up to request clarification or add additional context in comments.

3 Comments

I tried this: WebElement ele =(WebElement) ((JavascriptExecutor)webDriver).executeScript("return document.getElementById('1')"); ele.click(); but getting NullPointerException at the click
First switch to alert and then try.
if you want to check the existence of iframe, then you can use following code List<WebElement> iframes = driver.findelements(by.tagname("iframe"')); check the size() of list like iframes.size() to ensure the existence of iFrame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.