java - Swiching window in HtmlUnit -
when using selenium on firefoxdriver switching windows using following code
final set<string> allwindowid = driver.getwindowhandles(); final iterator<string> itr = allwindowid.iterator(); while (itr.hasnext()) { if (parentid == itr.next()) { parentid = itr.next(); } else { childid = itr.next(); } } driver.switchto().window(childid);
but same code not working when using htmlunitdriver. can ?
you comparing string references , not string values, use equals()
instead of ==
.
while (itr.hasnext()) { if (parentid.equals(itr.next())) { parentid = itr.next(); } else { childid = itr.next(); } } driver.switchto().window(childid);
for details: how compare strings in java?
also can re-write same method
while (itr.hasnext()) { if (!parentid.equals(itr.next())) { // no need reassign same value parentid childid = itr.next(); } } driver.switchto().window(childid);
Comments
Post a Comment