无法单击元素

问题描述 投票:0回答:1

我在点击IE11浏览器上的元素时遇到问题(网络只支持IE浏览器)。 到目前为止,我已经尝试过所有我知道的东西正在找到该元素,并且根据测试通过,看起来它被点击了,但没有发生任何事情。它没有被执行。这是HTML:

<li tabindex="-1" title="forward" class="ms-crm-CommandBarItem ms-crm-CommandBar-Menu ms-crm-CommandBar-Button" id="email|NoRelationship|Form|Mscrm.Form.email.Forward" style="display: inline-block; white-space: pre-line;" command="email|NoRelationship|Form|Mscrm.Form.email.Forward"><span tabindex="-1" class="ms-crm-CommandBar-Button ms-crm-Menu-Label" style="max-width: 200px;"><a tabindex="0" class="ms-crm-Menu-Label" onclick="return false"><img tabindex="-1" class="ms-crm-ImageStrip-forwardedemail_16 ms-crm-commandbar-image16by16" style="vertical-align: top;" src="/_imgs/imagestrips/transparent_spacer.gif"> <span tabindex="-1" class="ms-crm-CommandBar-Menu" style="max-width: 150px;" command="email|NoRelationship|Form|Mscrm.Form.email.Forward"> forward to rec</span><div class="ms-crm-div-NotVisible"> 
new object has been created </div>  </a> </span> </li>

这些只是我尝试过的一些内容,以下XPath语法实际上适用于同一页面中的其他元素。

WebDriverWait wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(30));
var element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//[@id='email|NoRelationship|Form|Mscrm.Form.email.Forward']")));
element.Click();

var element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id='email|NoRelationship|Form|Mscrm.Form.email.Forward']")));IJavaScriptExecutor executor = (IJavaScriptExecutor)_webdriver;
executor.ExecuteScript("arguments[0].click();", element);

我也试过使用Action类来点击,但没有任何作用。也只使用FindElement(By.Id(''))。在某些情况下,看起来鼠标悬停在元素上,但同样没有真正执行点击。

UPD:我试图点击一个按钮实际上在层次结构中有一个spana标签。我发现手动,按下按钮工作得很好。在第一次使用Selenium查找元素之前,按钮即被“锁定”,甚至在尝试点击它之前。

c# selenium internet-explorer-11
1个回答
1
投票

试试以下代码:

WebDriverWait wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("a.ms-crm-Menu-Label")));
element.Click();

PS:点击链接。 (a标签)。

希望它能帮到你!

© www.soinside.com 2019 - 2024. All rights reserved.