Question

<div class="flow-right">
    <button type="button" id="btnClear_page" class="uiButton" title="Clear" onmouseover="JSButtonUtils.doBtnOver(this)" onmousedown="JSButtonUtils.doBtnDown(this)" onmouseout="JSButtonUtils.doBtnOut(this)" onclick="if(JSButtonUtils.debounce(this, 1200)){ return false } else { return btnClear_page_click(this, true, true);}  ">
      <div class="uiButton-content">
        <div class="uiButton-label">Clear</div>
      </div>
    </button>
    <button type="button" id="btnSearch_page" class="uiButton primary" title="Search" onmouseover="JSButtonUtils.doBtnOver(this)" onmousedown="JSButtonUtils.doBtnDown(this)" onmouseout="JSButtonUtils.doBtnOut(this)" onclick="if(JSButtonUtils.debounce(this, 1200)){ return false } else { return btnSearch_page_click(this, true, true);}  ">
      <div class="uiButton-content">
        <div class="uiButton-label">Search</div>
      </div>
    </button>
</div>

I have above html code, button wrapped inside Div, I have tried to find the button and click on it, no luck and also tried clicking over Div no luck. Using IE9 browser and C#.

using (var browser = new IE("https://Site.com"))
            {
     browser.Div(Find.ByText("Search")).Click();
      browser.Button(Find.ById("btnSearch_page")).Click();
}
Was it helpful?

Solution

I have had flaky experiences with WatiN in the past and I have always used guard clauses in my WatiN code to fend off NullReferenceExceptions, like this:

using (var browser = new IE("https://Site.com"))
{
    var SearchDiv = browser.Div(Find.ByText("Search"));
    // Only try to click the DIV if we found it
    if(null != SearchDiv)
    {
        SearchDiv.Click();
    }

    var SearchButton = browser.Button(Find.ById("btnSearch_page"));
    // Only try to click the button if we found it
    if(null != SearchButton)
    {
        SearchButton.Click();
    }
}

OTHER TIPS

Iframe elements are considered as a different form elements,doesn't fall under the main form. using the below code we can click any child elements under the iframe.

WatiN.Core.Frame frame = browser.Frame(Find.ById("frameMain"));
                var buttons = frame.Button(Find.ById("btnSearch_page"));
                if (buttons.Exists)
                {
                    buttons.Click();
                    browser.WaitForComplete();
                }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top