【问题标题】:Xpath in IE11 not workingIE11 中的 Xpath 不工作
【发布时间】:2015-07-06 10:16:25
【问题描述】:

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

这是链接的 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>

硒代码

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>

【问题讨论】:

  • 能否发一张页面截图或链接到真实网页
  • 我将发布网页截图,因为此应用程序仅在内部网络中工作

标签: c# selenium xpath


【解决方案1】:

我解决了这个问题,实际上图像按钮位于 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");

感谢您的帮助。

【讨论】:

    猜你喜欢
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多