[英]Selenium webdriver c# - unable to click() element (element not null)
[英]Selenium - Unable to click on element c#
我有一個單擊樹的所有節點元素並驗證新頁面標題的測試。 我可以單擊除一個元素之外的每個元素。 該元素存在,我可以用鼠標單擊它,但是我無法通過測試單擊它,它也不會失敗。 任何幫助將不勝感激!
測試中存在問題的部分(使用了我沒有問題的元素來驗證懸停功能是否正常工作):
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>
確保您要檢查的元素具有單個匹配項。
如果在沒有給出任何例外的情況下無法正常點擊,我們可以使用以下方法進行點擊。
1. var button = document.getElementById("....");
button.click();
2. Actions action = new Actions(_driver);
action.MoveToElement(driver.FindElement(By.Id(".....")));
action.Click().Build().Perform();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.