Handling pop-up with different Browsers using WatiN
I am working with automating a Sharepoint application with WatiN. There are few screen where clicking on button or link additional information will be displayed in a light box pop
The Browser URL and Pop-up Url are different, hence am not able to get the 开发者_高级运维any reference of the objects.
Please help me out with this, all most all of my scripts will need to handle these kind of light boxes.
If your popup is, as I understand them, a page displayed in a new browser window, you will need to create a new WatiN browser instance to access this "popup".
WatiN offer multiple matching criteria to attach a browser using the method AttachTo(). It must be combine with a search specifier:
- By URL : Find.ByURL()
- By URI : Find.ByURI()
- By Windows Title : Find.ByTitle()
- By Window Handle : Find.By()
Here's an example for attaching a WatiN IE browser to an existing page, in this case your popup, using his window title :
IE myPopup = IE.AttachTo<IE>(Find.ByTitle("My Popup title"));
The search by title can use only a portion of the name. Following the same example as the previous one, the following should also match your popup :
IE myPopup = IE.AttachTo<IE>(Find.ByTitle("My Popup"));
As for the find by URL or URI, they may work the same way with a partial match (I'm speculate). So if you know what is the URL the popup open, it may be a better solution. Especially if the URL is more unique than your popup title, you'll reduce the chance to attach to a wrong browser.
精彩评论