简体   繁体   中英

Selenium IE Webdriver: Unable to switch to jQuery Modal window

在此处输入图片说明 I want to switch to jQuery Modal window which is generated when an image is clicked. However Selenium (IE Webdriver) is not able to recognize the modal window generated and unable to switch. No exception/error is displayed!

IE Version - 11 Selenium version - 2.53 IE WebDriver version - 2.53.1

The code I have tried for switching:

objMovePage.clickFromAccountPicker(); //Image clicked

Thread.sleep(2000);  //Wait for new window to show up
Set<String> windows = driver.getWindowHandles();

System.out.println(windows.size()); // This returns 1 always.


for(String handle: windows)
{
  driver.switchTo().window(handle);
}
System.out.println(driver.getTitle()); //Prints current window title

I have also tried driver.switchTo().window("<window name>"); // This also doesn't work. driver.switchTo().window("<window name>"); // This also doesn't work.

HTML Code for the image being clicked

<td style="height: 20px">
<input id="imgPickAcct" align="top" type="image" style="border-width:0px;" onclick="PickAcctClick(711269, 450, 300);" src="images/magnifyglass.gif" tabindex="-1" name="imgPickAcct">
</td>

JS function code

function PickAcctClick(intTransmissionID, intwidth, intheight)
        {
                var lstrPath = 'wfrmGetTransmittedAccounts.aspx?TransmissionID=' + intTransmissionID;
                var returnValues = openModal(lstrPath, intwidth, intheight);
                if (returnValues != undefined)
                {
                document.forms[0].txtFromAccountingID.value = returnValues[0].toString();
                document.forms[0].txtFromDept.value = returnValues[1].toString();
                document.forms[0].txtFromAcct.value = returnValues[2].toString();
                document.forms[0].txtFromCur.value = returnValues[3].toString();
                document.forms[0].txtFromProduct.value = returnValues[4].toString();
                if (isAnObject("txtFromChart1"))
                    {document.forms[0].txtFromChart1.value = returnValues[5].toString();}
                if (isAnObject("txtFromChart2"))
                    {document.forms[0].txtFromChart2.value = returnValues[6].toString();}
                if (isAnObject("txtFromChart3"))
                    {document.forms[0].txtFromChart3.value = returnValues[7].toString();}
                }
                return false;
        }

NOTE: This is not an alert or dialog window from showModalDialog. Edit: There is no iFrame.

driver.switchTo() is used for switching between frames, windows and tabs. A modal window is "regular" html markup like any div. You don't need to switch to it, you can use xpath (or css selectors etc) to select any element you'd like.

Edit:

If you popup is not found it's likely you have a timing problem (for example 2 seconds are not enough time). I'd suggest using an explicit wait (See WebDriverWait like it is used in this answer ). Explicit waiting is always a cleaner approach than just putting the thread to sleep.

I too faced the same window, refer the link and configure in regedit.exe

The first is to start your InternetExplorer in private mode. After that InternetExplorer will be started with clean session data and will not save changed session data at quiting. To do so you need to pass 2 specific capabilities to driver: ie.forceCreateProcessApi with true value and ie.browserCommandLineSwitches with -private value. Be note that it will work only for InternetExplorer 8 and newer, and Windows Registry HKLM_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main path should contain key TabProcGrowth with 0 value.

The second is to clean session during InternetExplorer starting. For this you need to pass specific ie.ensureCleanSession capability with true value to driver. This clears the cache for all running instances of InternetExplorer, including those started manually.

For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

Adding TabProcGrowth entry solved my problem.

I think opening private session can be ignored.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM