2

We started test automation on our web app (ASP.NET). We should've done it ages ago and the meantime the app has become complex so our Selenium progress is very slow. I'm completely new to Selenium and I have a situation, well, right from the start. Our app, upon clicking a button on the main form opens a dialog.

This how it looks like in the inspect element:

<div id="ModalPopupControl_PW-1" class="dxpcLite dxpclW dxpc-mainDiv dxpc-shadow" style="width: 975px; cursor: default; z-index: 12000; visibility: visible; display: table; position: absolute; height: 713px; left: 132px; top: 66px;">
  <div class="dxpc-header dxpc-withBtn" style="cursor:move;-khtml-user-select:none;" id="ModalPopupControl_PWH-1">
    <div class="dxpc-closeBtn" id="ModalPopupControl_HCB-1">
      <img class="dxWeb_pcCloseButton" src="/Client/DXR.axd?r=1_37-WyBvg" alt="[Close]">
    </div>
    <div class="dxpc-headerContent" style="padding-left: 0px !important; padding-right: 18px !important; line-height: 10px; height: 14px;">
      <span class="dxpc-headerText dx-vam" id="ModalPopupControl_PWH-1T"></span>
    </div>
    <b class="dx-clear">
    </b>
  </div>
  <div class="dxpc-contentWrapper" style="display: table; height: 692px;">
    <div class="dxpc-content" style="padding: 0px; display: block; height: 692px;" id="ModalPopupControl_PWC-1">
      <iframe id="ModalPopupControl_CIF-1" scrolling="auto" frameborder="0" src="Controls/NewDoc/NewDocumentPage.aspx" style="width: 100%; height: 100%; overflow: auto; backface-visibility: hidden; vertical-align: text-bottom;">  </iframe>
    </div>
  </div>
</div>

So, it's div, with an iframe in it.

I can select the dialog using an CssSelector, but no matter what the element WITHIN new pop-up dialog - I can't reach it using selenium.

My attempt to get it is pretty straightforward:

Driver.chrome.FindElement(By.CssSelector("#newDocumentControl_CallbackPanelShowGrids_rbSelection_RB1_I_D")).Click();

Error I get is:

{"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"#newDocumentControl_btnCancel\"}\n  (Session info: chrome=71.0.3578.98)\n  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)"}

I've tried SwitchTo().Alert, MoveTo element, searching by z index...

I'm using Chrome, Visual Studio 2017 and C#.

I could really, really use some tips...

1 Answer 1

1

In your DOM this element is not present

newDocumentControl_CallbackPanelShowGrids_rbSelection_RB1_I_D

can you please show the element exactly you want to select

does you want to select <iframe> ?

and if you want to select iframe

do as this

Driver.chrome.FindElement(By.id("ModalPopupControl_CIF-1")).Click();

or this

 WebElement iframeSwitch = driver.findElement(By.id("ModalPopupControl_CIF-1"));
 driver.switchTo().frame(iframeSwitch);
5
  • I don't believe this! It works! Oh, one more thing...when I'm done, I'll close the <iframe> on X or Cancel button. Will Selenium know that I'm back in the main window or should I somehow manually switch it back like you did on the <iframe>? Dec 14, 2018 at 10:32
  • Wait...URL is always the same. It's a dialog windows that I'm switching to. It has no URL. Once I'm done, I need to switch back to the main window.... Dec 14, 2018 at 11:33
  • @NikolaPepic sorry ! your right
    – Rao
    Dec 14, 2018 at 11:39
  • But I'm not sure how to approach this. In your example, you grabbed the ID of the dialog, then swithed to it. When I close it, it seems that Selenium still has it in focus and I can't grab elements in main to switch to it...because it is not in focus. How could I get around this? Dec 14, 2018 at 11:46
  • try this out driver.switchTo().defaultContent();
    – Rao
    Dec 14, 2018 at 11:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.