2015-07-06 105 views
0

我在C#中使用IE 11中的Selenium來自動執行某些任務。我能夠在IE中打開URL並點擊某個按鈕,但是我像其他xpath一樣陷入了一個問題,我點擊了一個圖像鏈接,但始終顯示xpath未找到。IE11中的Xpath無法正常工作

enter image description here

這裏是鏈接 我既ID名稱SRC等,但沒有成功嘗試過的HTML代碼。

<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> 
+0

你可以張貼頁面如何截圖或鏈接到真實的網頁 – Madhan

+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"); 

感謝您的幫助。