我有一个测试点击树的所有节点元素并验证新页面的标题。我可以让它点击除一个元素之外的每个元素。该元素存在,我可以用鼠标点击它,但我无法通过测试点击它,它也不会失败。任何帮助将不胜感激!
测试中遇到问题的部分(使用了一个我没有问题的元素来验证悬停功能是否正常工作):
IWebElement othernode = IWebDriverExtensions.FindElement(By.Id("node122")); // another element, this one functions properly
HandleMouseHoverEvent(othernode); // hover over functioning element - this is successful
IWebDriverExtensions.wait();
IWebElement findme = IWebDriverExtensions.FindElement(By.Id("node100015")); // element I want to click on
Console.WriteLine("displayed " + findme.Displayed); // check if wanted element is displayed - returns True
Console.WriteLine(findme.Text); // prints text successfully
HandleMouseHoverEvent(findme); // hover over the element I want to click on - this doesn't work, but does not error
IWebDriverExtensions.wait();
findme.Click(); // click on the element I want to click on - this doesn't work, but does not error
Console.WriteLine("clicked"); // this gets printed
输出:
displayed True
New Prospect & Assignment
clicked
以下是两个元素(node122有效,node100015没有):
<tr nodetype="child" nodesequence="122">
<td></td>
<td colspan="2"><span> </span><span id="node122" onclick="try{UpdateNodes(event, this, 'RedirectTab','Interest/Project','action.aspx?treestate=-14-&PageId=50&AppId=10&idnumber=000&AppHeaderName=Prospect+Tracking++-+Interest%2fProject&SelectedNodeSequence=122','Default.aspx?treestate=-14-&PageId=50&AppId=10&idnumber=000&AppHeaderName=Prospect+Tracking++-+Interest%2fProject&SelectedNodeSequence=122', 1)} catch(exp){ }" onmouseout="OnNodeMouseOut(event, this, 1)" onmouseover="OnNodeMouseOver(event, this)" class="menuchild" lvl="1">Interest/Project</span><span></span></td>
</tr>
<tr nodetype="child" nodesequence="100015">
<td></td>
<td colspan="2"><span> </span><span id="node100015" onclick="try{UpdateNodes(event, this, 'RedirectTab','New Prospect & Assignment','action.aspx?treestate=-14-&PageId=50&AppId=80&idnumber=000&AppHeaderName=Prospect+Tracking++-+New+Prospect+%26+Assignment&SelectedNodeSequence=100015','Default.aspx?treestate=-14-&PageId=50&AppId=80&idnumber=000&AppHeaderName=Prospect+Tracking++-+New+Prospect+%26+Assignment&SelectedNodeSequence=100015', 1)} catch(exp){ }" onmouseout="OnNodeMouseOut(event, this, 1)" onmouseover="OnNodeMouseOver(event, this)" class="menuchild" lvl="1">New Prospect & Assignment</span><span></span></td>
</tr>
答案 0 :(得分:0)
确保检查中的元素具有单一匹配。
如果正常点击不提供任何例外情况,我们可以使用以下方法点击。
1. var button = document.getElementById("....");
button.click();
2. Actions action = new Actions(_driver);
action.MoveToElement(driver.FindElement(By.Id(".....")));
action.Click().Build().Perform();