This is a migrated thread and some comments may be shown as answers.

Trouble verifying if certain elements are showing on page

2 Answers 36 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Felix
Top achievements
Rank 1
Felix asked on 14 Jun 2012, 07:37 PM
Hi all,

I'm trying to close some slide outs and in page pop ups when they show (they only show after cookies are cleared when you first visit this page)

I've tried a few things but i'm not getting the results i need. Examples i've found use .isVisible which i couldnt find in my available options.<div class="popup-modal most-visible" style="display: block; z-index: 102; width: auto; height: auto; top: 159px; left: 680px;">
Here are the 2 snippets of code i want to verify if they are "showing on the page currently"

<div class="popup-modal most-visible" style="display: block; z-index: 102; width: auto; height: auto; top: 159px; left: 680px;">
<div class="qsc-popup-dialog" style="display: block; visibility: visible;">
<div class="close-button" title="Close Dialog"></div>
<div class="header">Product Type</div>
<div id="startupHelp" class="body" style="width: auto; height: auto; overflow: auto;">
<div class="footer">
</div>
</div>
 
 
<div class="sf-pagehelp" style="left: 0px;">
<a class="sf-pagehelp-pin" href="#" style="display: none;"></a>
<div class="sf-pagehelp-hdr">
<h3>Page Help</h3>
<div class="sf-pagehelp-subtext">Quick answers for the current page.</div>
</div>
<div class="sf-pagehelp-wrap">
<div class="sf-pagehelp-toggle"></div>
</div>


I think i'm having issues because the code will always be in the source so what i'm trying now will never be false...

browser.RefreshDomTree();
            //if help is open close it.
            if (browser.Find.ById("sf-pagehelp") != null)
            {
                browser.Actions.Click(browser.Find.ById("sf-pagehelp-toggle"));
            }
            else if (browser.Find.ByXPath("/html/body/div[3]/div/div[4]/div/span/a/span/span/input") != null)
            {
                browser.Actions.Click(browser.Find.ByXPath("/html/body/div[3]/div/div[4]/div/span/a/span/span/input"));
            }

any help is appreciated.

thanks!

2 Answers, 1 is accepted

Sort by
0
Jonas
Top achievements
Rank 2
answered on 18 Jun 2012, 12:01 PM
Hello Felix,

There is a few thing in the Find.Strategy that you can use depending on what will happen if the element is not found.
I don't know if this is what you are looking for?

window.Find.Strategy = FindStrategy.AlwaysWaitForElementsVisible;
window.Find.Strategy = FindStrategy.WhenNotVisibleReturnElementProxy;
window.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull;
window.Find.Strategy = FindStrategy.WhenNotVisibleThrowException;

Best Regards
Jonas
0
Anthony
Telerik team
answered on 19 Jun 2012, 04:54 PM
Hello Felix,

I crafted a test against Bing.com that successfully implements your solution. If you clear cookies and navigate to Bing, there's a gray banner at the bottom that says "Bing brings search and people together." The containing <div> is:

<div id="bnp.nid.9092" style="display: block;">

Clicking the "X" on that banner causes the containing <div> to change:

<div id="bnp.nid.9092" style="display: none;">

That meant it was not seen by Test Studio, so the following code succeeded:

Manager.LaunchNewBrowser();
ActiveBrowser.ClearCache(ArtOfTest.WebAii.Core.BrowserCacheType.Cookies);
 
ActiveBrowser.NavigateTo("http://bing.com");
System.Threading.Thread.Sleep(5000);
ActiveBrowser.RefreshDomTree();
 
HtmlDiv parent = Find.ById<HtmlDiv>("bnp.nid.9092");
 
if (parent != null)
{
    HtmlDiv center = parent.Find.ById<HtmlDiv>("hpusCtnr");
    HtmlDiv x = center.Find.ByTagIndex<HtmlDiv>("div", 0);
    x.MouseClick();
}
else
{
    Find.ById<HtmlInputText>("sb_form_q").Text = "TELERIK";
}
System.Threading.Thread.Sleep(1500);

If you require further assistance, please provide a public site with a complete code sample so we can reproduce the issue.

Regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Felix
Top achievements
Rank 1
Answers by
Jonas
Top achievements
Rank 2
Anthony
Telerik team
Share this question
or