user1645067 user1645067 - 2 months ago 14
Java Question

Unable to click on button which is situate on popup made by <div> using Selenium WebDriver

HTML CODE

</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>


Right now I am working to automate web application which is developed in Qooxdoo frame work (it's javaScript framework) using selenium Web Driver with TestNG.

In this I already achieve a few things but there are some pop ups which are made using nested
<div>
and selenium popup handler can not handle that.
By using action class I can write in text area {by below mention selenium code }which is show in pop up (find the attachment) but I cannot click on the button ( OK , CANCEL).

// 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


I tried to switch focus by using action class again to the div in which the buttons are present but then also I cannot.

Error Log :

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"....

Answer

Try following code and let me know in case of any exceptions:

wd.findElement(By.xpath("//div[text()='OK']")).click();
Comments