无法单击 <div> 使用 Selenium WebDriver 制作的弹出窗口中的按钮
Unable to click on button which is situate on popup made by <div> using Selenium WebDriver
HTML 代码
</div>
<div class="qx-outSet" qxselectable="off" style="overflow:...>
<div class="qx-button" tabindex="4" qxselectable="off" style="overflow:...>
******************************************** I have to click on bellow OK button ****************************
<div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis; box-sizing: border-box; position: absolute; cursor: default; -moz-user-select: none; color: rgb(26, 26, 26); font-family: Arial,"Liberation Sans",sans-serif; font-size: 14px; left: 24px; top: 3px; width: 21px; height: 16px;" qxselectable="off" qxanonymous="true">OK</div>
</div>**
<div class="qx-button" tabindex="5" qxselectable="off" style="overflow: hidden; box-sizing: border-box; position: absolute; outline: medium none; -moz-user-select: none; cursor: default; padding: 3px 9px; left: 88px; top: 9px; width: 70px; height: 24px;">
<div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis; box-sizing: border-box; position: absolute; cursor: default; -moz-user-select: none; color: rgb(26, 26, 26); font-family: Arial,"Liberation Sans",sans-serif; font-size: 14px; left: 12px; top: 3px; width: 45px; height: 16px;" qxselectable="off" qxanonymous="true">Cancel</div>
</div>
现在我正在使用带有 TestNG 的 selenium Web 驱动程序来自动化在 Qooxdoo 框架(它是 javaScript 框架)中开发的 Web 应用程序。
在此我已经实现了一些事情,但是有一些弹出窗口是使用嵌套 <div>
制作的,而 selenium 弹出窗口处理程序无法处理。
通过使用操作 class 我可以在文本区域中写入{通过下面提到的 selenium 代码},它显示在弹出窗口中(找到附件)但我无法点击按钮(确定,取消)。
// wd is WebDriver Object
WebElement element = wd.findElement(By.className("qx-window")); // qx-window is class name of div in which text area is present
Actions actions = new Actions(wd);
actions.moveToElement(element).click().perform();
Thread.sleep(5000);
// write text in text area
wd.findElement(By.tagName("textarea")).sendKeys("TEST");
wd.findElement(By.xpath(".//*[@id='demindoRoot']/div[4]/div[2]/div[2]/div[1]")).click(); // CODE TO CLICK ON "OK" BUTTON
我尝试再次使用操作 class 将焦点切换到按钮所在的 div,但我也不能。
错误日志:
org.openqa.selenium.NoSuchElementException: 无法定位元素:{"method":"xpath","selector":"...
试试下面的代码,如果有任何异常请告诉我:
wd.findElement(By.xpath("//div[text()='OK']")).click();
HTML 代码
</div>
<div class="qx-outSet" qxselectable="off" style="overflow:...>
<div class="qx-button" tabindex="4" qxselectable="off" style="overflow:...>
******************************************** I have to click on bellow OK button ****************************
<div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis; box-sizing: border-box; position: absolute; cursor: default; -moz-user-select: none; color: rgb(26, 26, 26); font-family: Arial,"Liberation Sans",sans-serif; font-size: 14px; left: 24px; top: 3px; width: 21px; height: 16px;" qxselectable="off" qxanonymous="true">OK</div>
</div>**
<div class="qx-button" tabindex="5" qxselectable="off" style="overflow: hidden; box-sizing: border-box; position: absolute; outline: medium none; -moz-user-select: none; cursor: default; padding: 3px 9px; left: 88px; top: 9px; width: 70px; height: 24px;">
<div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis; box-sizing: border-box; position: absolute; cursor: default; -moz-user-select: none; color: rgb(26, 26, 26); font-family: Arial,"Liberation Sans",sans-serif; font-size: 14px; left: 12px; top: 3px; width: 45px; height: 16px;" qxselectable="off" qxanonymous="true">Cancel</div>
</div>
现在我正在使用带有 TestNG 的 selenium Web 驱动程序来自动化在 Qooxdoo 框架(它是 javaScript 框架)中开发的 Web 应用程序。
在此我已经实现了一些事情,但是有一些弹出窗口是使用嵌套 <div>
制作的,而 selenium 弹出窗口处理程序无法处理。
通过使用操作 class 我可以在文本区域中写入{通过下面提到的 selenium 代码},它显示在弹出窗口中(找到附件)但我无法点击按钮(确定,取消)。
// wd is WebDriver Object
WebElement element = wd.findElement(By.className("qx-window")); // qx-window is class name of div in which text area is present
Actions actions = new Actions(wd);
actions.moveToElement(element).click().perform();
Thread.sleep(5000);
// write text in text area
wd.findElement(By.tagName("textarea")).sendKeys("TEST");
wd.findElement(By.xpath(".//*[@id='demindoRoot']/div[4]/div[2]/div[2]/div[1]")).click(); // CODE TO CLICK ON "OK" BUTTON
我尝试再次使用操作 class 将焦点切换到按钮所在的 div,但我也不能。
错误日志:
org.openqa.selenium.NoSuchElementException: 无法定位元素:{"method":"xpath","selector":"...
试试下面的代码,如果有任何异常请告诉我:
wd.findElement(By.xpath("//div[text()='OK']")).click();