IE11中的Xpath无法正常工作

时间:2015-07-06 10:16:25

标签: c# selenium xpath

我在IE 11中使用Selenium和C#来自动执行某项任务。我能够在IE中打开URL并单击某个按钮但我遇到了一个问题,就像其他xpath我点击一个图像链接但它总是显示未找到xpath。

enter image description here

以下是链接的HTML代码 我尝试使用ID名称src等但没有成功。

    <li>   
    <INPUT disabled id=ucTicketDetail1_btnClose title="- Cannot close    
    due to     CM stage. Ticket must be in CM Approved or Preproduction Approved     stage.&#10;-
  You don't have permission to close.&#10;- No longer editable."      style="BORDER-LEFT-WIDTH: 0px; 
    BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH:  ; BORDER-TOP-    WIDTH: 0px"    src="../images/tasks_disabled.gif" type=image     name=ucTicketDetail1$btnClose>
    <li>

Selenium Code

driver.FindElement(By.XPath("//input[@id='ucTicketDetail1_btnClose']")).Click();

请帮助我如何为此编写xpath,因为此应用程序仅在IE中打开。

这是带样式的扩展代码

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
LI {
    margin: 0;
    padding: 0;
}
LI {
    list-style: none;
}
LI {
    float: left;
    line-height: 15px;
    margin: 0px 0px 0px 5px;
}
LI {
    float: left;
    line-height: 15px;
    margin: 0px 0px 0px 5px;
}
UL {
    margin: 0;
    padding: 0;
}
UL {
    list-style-image: none;
    list-style-position: outside;
    list-style-type: none;
}
UL {
    list-style-image: none;
    list-style-position: outside;
    list-style-type: none;
}
DIV {
    margin: 0;
    padding: 0;
}
.TicketDetailHeaderRight {
    float: right;
}
.TicketDetailHeader {
    margin: 0px;
    padding: 0 5px 5px;
    min-height: 15px;
}
.SectionBody {
    margin: 5px;
}
.Section {
    border: 1px solid #000;
}
FORM {
    margin: 0;
    padding: 0;
}
BODY {
    color: #000;
}
BODY {
    margin: 0;
    padding: 0;
}
BODY {
    font: 13px/1.231 arial,helvetica,clean,sans-serif;
    font-size: ;
    font: x-small;
}
BODY {
    margin: 0px;
    padding: 0px;
    color: #000000;
    font-family: Verdana;
    font-size: 83%;
    line-height: normal;
}
HTML {
    margin: 0px;
    padding: 0px;
    color: #000000;
    font-family: Verdana;
    font-size: 83%;
    line-height: normal;
}
INPUT {
    margin: 0;
    padding: 0;
}
INPUT {
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
}
</style>
</head>

<BODY><FORM id=formTicketDetail method=post name=formTicketDetail action=wfTicketDetail.aspx?TicketId=C110041540 _events="[object Object]">
<DIV class=Section>
<DIV class=SectionBody>
<DIV class=TicketDetailHeader>
<DIV id=ucTicketDetail1_divBtnBar class=TicketDetailHeaderRight>
<DIV id=ucTicketDetail1_updatePanelPostSaveActions>
<DIV id=ucTicketDetail1_divPostSaveActions class=PostSaveActions>
<UL>
<LI><INPUT disabled id=ucTicketDetail1_btnClose title="- Cannot close due to CM stage. Ticket must be in CM Approved or Preproduction Approved stage.&#10;- You don't have permission to close.&#10;- No longer editable." style="BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-TOP-WIDTH: 0px" src="../images/tasks_disabled.gif" type=image name=ucTicketDetail1$btnClose> </LI></UL></DIV></DIV></DIV></DIV></DIV></DIV></FORM></BODY>
</html>

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,实际上图像按钮位于2 iframe下面。我切换到Iframe,然后开始工作。 这是代码

driver.SwitchTo().Frame("wfMainIFrame");
        driver.SwitchTo().Frame("wfCaseIFrame");

        string atb = driver.FindElement(By.XPath("//input[@id='ucTicketDetail1_btnClose']")).GetAttribute("disabled");
        string title = driver.FindElement(By.XPath("//input[@id='ucTicketDetail1_btnClose']")).GetAttribute("title");

感谢您的帮助。