[英]not able to click button using watin
<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>
我上面有html代碼,按鈕包裹在Div里面,我試圖找到按鈕並單擊它,沒有運氣,還嘗試單擊Div沒有運氣。 使用IE9瀏覽器和C#。
using (var browser = new IE("https://Site.com"))
{
browser.Div(Find.ByText("Search")).Click();
browser.Button(Find.ById("btnSearch_page")).Click();
}
我過去在WatiN上經歷過斷斷續續的經歷,並且我一直在我的WatiN代碼中使用guard子句來抵御NullReferenceException
,如下所示:
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();
}
}
iframe元素被視為不同的表單元素,不屬於主要表單。 使用以下代碼,我們可以單擊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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.