无法单击“保存并关闭”标签

时间:2017-06-14 21:10:03

标签: selenium-webdriver

请帮助为什么不能点击下面的保存并关闭图片?它显示错误,没有这样的元素

action.MoveToElement(driver.FindElement(By.XPath("//*[@class='ms-crm-Menu-Label']"))).Click().Build().Perform();
driver.FindElement(By.XPath("//*[@class='ms-crm-ImageStrip-Save_16 ms-crm-commandbar-image16by16']/img")).Click();

这是HTML。

<li tabindex="-1"
title="Save &amp; Close (ALT+S) &#10;&#10;Save and close this Lead."
class="ms-crm-CommandBarItem ms-crm-CommandBar-Menu ms-crm-CommandBar-Button"
id="lead|NoRelationship|Form|Mscrm.Form.lead.SaveAndClose" style="display: inline-block; white-space: pre-line;"
command="lead|NoRelationship|Form|Mscrm.SaveAndClosePrimary">
<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-SaveAndClose_16 ms-crm-commandbar-image16by16"
            style="vertical-align: top;" src="/_imgs/imagestrips/transparent_spacer.gif"></img>
        <span tabindex="-1" class="ms-crm-CommandBar-Menu" style="max-width: 150px;"
            command="lead|NoRelationship|Form|Mscrm.SaveAndClosePrimary"> Save &amp; Close </span>
        <div class="ms-crm-div-NotVisible"> Save and close this Lead. </div>
    </a>
</span>

1 个答案:

答案 0 :(得分:0)

Webdriver无法使用您使用的xpath找到控件。请尝试以下方法:

driver.FindElement(By.XPath("//li/span/a[@class='ms-crm-Menu-Label']/span[@command='lead|NoRelationship|Form|Mscrm.SaveAndClosePrimary']")).Click();

请告诉我,它是否适合您。