English 中文(简体)
WatiN:无法分两次点点击“不能找到要素”错误
原标题:WatiN: Unable to click an Element twice - "Could not find element" error
  • 时间:2012-01-13 15:09:00
  •  标签:
  • c#
  • watin

我正在讨论一个问题,即我需要两次点击一个因素。 该元件被点击第一次在网页上扩大树木,第二次关闭了树木。 第一次点击该元素没有任何问题。

这里是我与以下各方合作的超文本守则的一部分:(我点击的内容是标记)。

<div id="uasMainForm:uasTabs:0:agencyTree-d-rt-c" name="c">
    <div title="" class="iceTreeRow" id="uasMainForm:uasTabs:0:agencyTree-d-4" name="nd">
        <a id="uasMainForm:uasTabs:0:agencyTree:4" onclick="document.forms[ uasMainForm ][ uasMainForm:uasMainForm:uasTabs:0:agencyTree_idtn ].value= 4 ;iceSubmitPartial( document.forms[ uasMainForm ], this,event); return false;" onblur="setFocus(  );" href="javascript:;">

The weird thing is, if I run the second click immediately after running the first it closes the tree perfectly, but if I break it up with a MessageBox or some other code it throws an error when trying to perform the second click.

这里的法典是行之有效的:

agency = ie.ElementOfType<Div>(Find.ByText(agencyName));
agencyTab = agency.ElementWithTag("a", Find.ByIndex(0));
agencyTab.Click();

//MessageBox.Show("Hey!");
agencyTab.Click();

这里的法典不可行:

agency = ie.ElementOfType<Div>(Find.ByText(agencyName));
agencyTab = agency.ElementWithTag("a", Find.ByIndex(0));
agencyTab.Click();

MessageBox.Show("Hey!");
agencyTab.Click();

上述法典犯了错误: 不能找到一个要素对等标准:指数=0

我也曾尝试过Find。 ById, und ByIndex, with the same results. 任何人在打破两个点击事件时,是否能够说明造成这一错误的是什么,而点击事件却又回头来的时候,怎么说呢?

最佳回答

我仍然不清楚为什么出现这一问题,但我找到了解决办法。 首先,在我第一次点击之前,我可以不掉载有离婚权利的伊德:

var agency = ie.ElementOfType<Div>(Find.ByText(agencyName));

//Set current agency Id
currentAgency = agency.Id;

var agencyTab = agency.ElementWithTag("a", Find.ByIndex(0));
agencyTab.Click();

接着,当我想进行第二次点击时,我利用我先前所挽救的Id I再次找到了隔 the:

//Close old agency s tree
var agency2 = ie.ElementOfType<Div>(Find.ById(currentAgency));
var agencyTab2 = agency2.ElementWithTag("a", Find.ByIndex(0));
agencyTab2.Click();
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签