Dhaval Atri Dhaval Atri - 4 years ago 129
Java Question

Unable to set focus on pop up

[![enter image description here][1]][1]HTML code is shown in Screenshot [![enter image description here][2]][2]

I tried with Action class

WebElement element = InspectationOrder.wd.findElement(By.xpath("//div[@class='qx-window']"));
Actions actions = new Actions(InspectationOrder.wd);
actions.moveToElement(element).click().build().perform();


but found
"java.lang.NullPointerException"
while i tried to move focus.
but same action code works for other area in application

Also tried with
for (String popup : wd.getWindowHandles())

{

wd.switchTo().window(popup);

}


but not working :(
May be issue with z-index but m don't have more idea about the same .

Answer Source

Selenium latest version(Selenium 3 with GeckDriver ) automatically handles set focus. Previously I am using selenium 2 in which we have to setfocus on new element.But in selenium 3 with GecoDriver we have no need to worry about small popups. In my whole automation script selenium 3 handles setfocus[ Not fully but at basic level ] for me and works form me.

Use full links. LINK-1 [LINK-2] -Thanks Dhaval

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download