Handling dynamically changing element id - using selenium webdriver

3,139 views
Skip to first unread message

Ranjithkumar

unread,
Jan 22, 2013, 5:51:12 AM1/22/13
to seleniu...@googlegroups.com
I m having the login page, when click login button it opens the new tab.

i moved the control to new window using,

driver.switchTo().window("windowname");

// done some stuffs in new window.

When I click one "Button" it will open the new popup (that popup is not a normal window it is a iframe).

I have selected a popup window using,

driver.switchTo().frame("frameName");

That popup has the list of records; each record has the separate "select" option (with the dynamically changing id's).

driver.findElement(By.xpath("//a[@id='radgrdPeople_ctl00_ctl04_lnkSelect']")).click();
When selecting the record from list, the popup window will be closed and the page will get refreshed.

Now I want to return the control to my parent window for doing some other stuff.

The record got selected successfully. But i could not able to focus the parent window again.

I have tried:

driver.switchTo().defaultcontent(); 

driver.switchTo().window("");

And driver.getWindowHandles()

Still I m getting the same problem.

I don't know whether I have to use any java script executor for handling the dynamically changing element id's.

Could u any one please help me on this....

Thanks in Advance.

By K.Ranjithkumar

Michael Wowro

unread,
Jan 23, 2013, 5:00:05 AM1/23/13
to seleniu...@googlegroups.com
Hi,

are you sure that you're not mixing the terms tab and window?
are you sure, that you're saving the handle before you switch? http://stackoverflow.com/a/9195632/1777526

Yours Michael

Ranjithkumar

unread,
Jan 23, 2013, 6:06:49 AM1/23/13
to seleniu...@googlegroups.com
Hi Michale,

First Thanks a lot for your reply.

From this blog, when i use the following condition, then it does not switched me to the popup,

 if(!popupHandle.contains(mwh)):.

But when i use with out this if loop, it switched to pop up window. but i m facing same previous pbm.

My Code is:

  String oldWindow=driver.getWindowHandle();
   
    driver.findElement(By.xpath("//input[@id='imgFetch']")).click();
    Thread.sleep(5000);
      
    Set s=driver.getWindowHandles();

    Iterator ite=s.iterator();

    while(ite.hasNext())
    {
      String popupHandle=ite.next().toString();
     
        driver.switchTo().window(popupHandle);
                  
                  driver.switchTo().frame("frame0");
                  
                  driver.findElement(By.xpath("//input[@id='txtName']")).sendKeys("test");
                  driver.findElement(By.xpath("//input[@id='imgbtnSearch']")).click();
                  Thread.sleep(10000);
                                                                      
                  driver.switchTo().window(mwh);
      
      }


murali

unread,
Jan 24, 2013, 1:24:25 AM1/24/13
to seleniu...@googlegroups.com
Hi,

Is there any editors/active elements where cursor blinks on main window after register? 

like this issue, switch to active element and to default/window helps me once..

Ranjithkumar

unread,
Jan 24, 2013, 3:11:27 AM1/24/13
to seleniu...@googlegroups.com
hi Murali,

for me after selecting the record, the main window will be refreshed.


raghu ayyana

unread,
Jun 21, 2013, 3:22:24 AM6/21/13
to seleniu...@googlegroups.com
Hi,
  
   After using this code
driver.switchTo().defaultcontent();
you need to close the frame,Frame having an closetab
Then u can handle parent window.

Reply all
Reply to author
Forward
0 new messages