【问题标题】:Can't click an element无法单击元素
【发布时间】:2018-01-01 22:15:54
【问题描述】:

我在 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 找到元素时,即使在尝试单击它之前,该按钮也会“锁定”。

【问题讨论】:

  • 您在问题中没有真正提到您要点击哪个WebElement
  • 这实际上是一个按钮。
  • 按钮包含什么?任何text 或任何其他属性?

标签: c# selenium internet-explorer-11


【解决方案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 标签)。

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    相关资源
    最近更新 更多