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:
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!