2013-06-12 123 views
0

在我的應用程序中,註銷是一個雙向過程。當您點擊主屏幕上的註銷鏈接時,會彈出一個確認註銷的彈出窗口。彈出註銷按鈕

現在,彈出窗口中有兩個按鈕('註銷'和'取消')。問題是我無法點擊其中任何一個。

使用Firebug控制檯,我確認我使用的XPath是正確的。但是當在webdriver中使用相同的Xpath時,它無法找到對象。

上彈出按鈕的Xpath:// DIV [3]/DIV/DIV/DIV [2]/DIV /一個/跨度

代碼而我試圖:

IWebElement LogoutButton = WebDriver.FindElement(By.XPath("//div[3]/div/div/div[2]/div/a/span")); 
     LogoutButton.Click(); 

有什麼具體的方法可以在這裏使用?請告訴我。

歡呼

編輯*

<div id="ext-comp-1084" class="x-window x-layer x-window-default x-closable x-window-closable x-window-default-closable x-popup" tabindex="-1" style="opacity: 1; width: 250px; height: 145px; right: auto; left: 755px; top: 147px; z-index: 19000;"> 
<div id="ext-comp-1084_header" class="x-window-header ext-header ext-header-horizontal x-docked x-unselectable x-window-header-default x-horizontal x-window-header-horizontal x-window-header-default-horizontal x-top x-window-header-top x-window-header-default-top x-docked-top x-window-header-docked-top x-window-header-default-docked-top" style="width: 250px; right: auto; left: 0px; top: 0px;"> 
<div id="ext-comp-1084-body" class="x-window-body x-window-body-default x-closable x-window-body-closable x-window-body-default-closable x-window-body-default x-window-body-default-closable" style="width: 250px; left: 0px; top: 52px; height: 49px;"> 
<div id="toolbar-1086" class="x-toolbar x-docked x-toolbar-default x-docked-bottom x-toolbar-docked-bottom x-toolbar-default-docked-bottom x-box-layout-ct" style="width: 250px; right: auto; left: 0px; top: 101px;"> 
<div id="toolbar-1086-innerCt" class="x-box-inner " role="presentation" style="width: 250px; height: 44px;"> 
<div id="toolbar-1086-targetEl" class="x-box-target" style="width: 250px;"> 
<div id="tbspacer-1087" class="x-toolbar-spacer x-box-item x-toolbar-item x-toolbar-spacer-default" style="right: auto; left: 0px; margin: 0px; width: 50px; top: 22px;"></div> 
<div id="button-1088" class="x-btn green x-exclude x-unselectable x-box-item x-toolbar-item x-btn-default-toolbar-small x-noicon x-btn-noicon x-btn-default-toolbar-small-noicon" style="border-width: 1px; width: 100px; right: auto; left: 50px; margin: 0px; top: 8px;"> 
<div id="button-1088-btnWrap" class="x-btn-wrap" unselectable="on"> 
<a id="button-1088-btnEl" class="x-btn-button" tabindex="0" unselectable="on" hidefocus="on" role="button"> 
<span id="button-1088-btnInnerEl" class="x-btn-inner x-btn-inner-center" unselectable="on">Logout</span> 
<span id="button-1088-btnIconEl" class="x-btn-icon-el " style="" unselectable="on" role="img"></span> 
</a> 
</div> 
</div> 
<div id="button-1089" class="x-btn gray x-exclude x-unselectable x-box-item x-toolbar-item x-btn-default-toolbar-small x-noicon x-btn-noicon x-btn-default-toolbar-small-noicon" style="border-width: 1px; width: 80px; right: auto; left: 160px; margin: 0px; top: 8px;"> 
<div id="button-1089-btnWrap" class="x-btn-wrap" unselectable="on"> 
<a id="button-1089-btnEl" class="x-btn-button" tabindex="0" unselectable="on" hidefocus="on" role="button"> 
<span id="button-1089-btnInnerEl" class="x-btn-inner x-btn-inner-center" unselectable="on">Cancel</span> 
<span id="button-1089-btnIconEl" class="x-btn-icon-el " style="" unselectable="on" role="img"></span> 
</a> 
</div> 
</div> 
</div> 
</div> 
</div> 
</div> 
+0

您是否嘗試過等待元素,無論是通過隱式還是顯式等待? –

+0

發表HTML代碼...是的,我已經嘗試了2000毫秒顯式等待...此外,而不是Click(),我試過使用ClickWhenVisible(); – user2434600

+0

爲了清楚起見,嘗試通過By.linkText(「Logout」)或By.xpath(「// a [text()='Logout']」)'來查找元素。你是否能夠以任何方式找到元素,或根本沒有?一如既往,你有沒有嘗試在另一個瀏覽器?每次都會一致地失敗嗎?與往常一樣,2秒可能不夠... –

回答

0

1)首先使用下面的代碼

String mainWindow = driver.getWindowHandle(); 

2)//代碼,點擊退出鏈接保存主窗口的實例在主屏幕上

3)然後切換控制的webdriver彈出使用以下代碼

for(String childWindow : driver.getWindowHandles()){ 
     driver.switchTo().window(childWindow); 
    } 

4)//代碼點擊彈出,(「退出」和「取消」)。