请帮助为什么不能点击下面的保存并关闭图片?它显示错误,没有这样的元素
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 & Close (ALT+S) 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 & Close </span>
<div class="ms-crm-div-NotVisible"> Save and close this Lead. </div>
</a>
</span>
答案 0 :(得分:0)
Webdriver无法使用您使用的xpath找到控件。请尝试以下方法:
driver.FindElement(By.XPath("//li/span/a[@class='ms-crm-Menu-Label']/span[@command='lead|NoRelationship|Form|Mscrm.SaveAndClosePrimary']")).Click();
请告诉我,它是否适合您。