代码之家  ›  专栏  ›  技术社区  ›  JumpIntoTheWater

无法单击元素

  •  0
  • JumpIntoTheWater  · 技术社区  · 8 年前

    我在IE11浏览器上单击元素时遇到问题(web仅支持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:我试图单击一个按钮,实际上在层次结构的后面有一个 span a 标签。 我发现手动按下按钮效果很好。当第一次找到含硒元素时,甚至在尝试单击之前,按钮就被“锁定”。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Ratmir Asanov    8 年前

    请尝试以下代码:

    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 标签)。

    希望对你有帮助!