Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 弹出注销按钮_Xpath_Selenium Webdriver - Fatal编程技术网

Xpath 弹出注销按钮

Xpath 弹出注销按钮,xpath,selenium-webdriver,Xpath,Selenium Webdriver,在我的应用程序中,注销是一个双向过程。当您单击主屏幕上的注销链接时,将打开一个弹出窗口以确认注销 现在,在弹出窗口中有两个按钮(“注销”和“取消”)。问题是我无法点击其中任何一个 使用Firebug控制台,我确认了我使用的XPath是正确的。但是在webdriver中使用相同的Xpath时,它无法定位对象 弹出窗口上按钮的Xpath://div[3]/div/div/div[2]/div/a/span 我正在尝试的代码: IWebElement LogoutButton = WebDriver.

在我的应用程序中,注销是一个双向过程。当您单击主屏幕上的注销链接时,将打开一个弹出窗口以确认注销

现在,在弹出窗口中有两个按钮(“注销”和“取消”)。问题是我无法点击其中任何一个

使用Firebug控制台,我确认了我使用的XPath是正确的。但是在webdriver中使用相同的Xpath时,它无法定位对象

弹出窗口上按钮的Xpath://div[3]/div/div/div[2]/div/a/span

我正在尝试的代码:

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>

注销
取消
1)首先使用以下代码保存主窗口的实例

String mainWindow = driver.getWindowHandle();
for(String childWindow : driver.getWindowHandles()){
        driver.switchTo().window(childWindow);
    }
2) //单击主屏幕上的注销链接的代码

3) 然后使用下面的代码将webdriver控件切换到弹出窗口

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

4) //单击弹出窗口(“注销”和“取消”)的代码。

您是否尝试过通过隐式或显式等待来等待元素?发布了HTML代码…是的,我尝试过将2000毫秒的显式等待…此外,我尝试过使用ClickWhenVisible()代替click();为清楚起见,请尝试通过.linkText(“注销”)或.xpath(“//a[text()='Logout']”)查找元素。您是否能够以任何方式定位元素,或者根本无法定位?和往常一样,您是否尝试过使用其他浏览器?它每次都会失败吗?像往常一样,2秒可能不够……是的……即使我认为2秒也不够……所以我在注销之前插入了一个断点并尝试调试它……仍然没有用……问题是WebElement完美地定位了注销按钮……但是“LogoutButton.Click();”失败。。不知道为什么它不能点击那个。。