Selenium webdriver click operation issue

109 views
Skip to first unread message

vimal chand

unread,
Jul 13, 2015, 2:20:12 PM7/13/15
to webd...@googlegroups.com
Selenium webdriver does not pass the parent window reference to the child window on a click operation( if the click involves passing of values to the child window from parent or viceversa).  Consider 2 html files a.html and b.html. a.html contains a textbox(input box) and a link.If the user clicks link, b.html should be opened and the entered text in a.html should be displayed as a alert.This works fine when the clicking operation is done manually.But if the selenium webdriver is involved, we have a problem. It throws document(parent reference) is null or undefined error.

I have raise the same issue in other selenium forum as well. Please find the details in the following URL. Please help


Thanks
Vimal

darrell

unread,
Jul 14, 2015, 5:23:19 PM7/14/15
to webd...@googlegroups.com
How are you creating the two windows? Manually, do you:
  1. Open a URL in the browser
  2. Open a new tab in the browser
  3. Enter a second URL in the browser
  4. Click an element in the first browser
  5. Receive the event in the second browser window
Or are you doing:
  1. Open a URL in the browser
  2. Click a link in the parent window which opens a new window
  3. Click an element in the first browser
  4. Receive the event in the second browser window

How you simulate these with WebDriver can be very different. If you create an instance of WebDriver, e.g. driver, then create a second instance of WebDriver, e.g. driver2, they are not aware of each other. They are two browsers running from different profiles. If you want to open a second window from the same profile you want to have a look at http://darrellgrainger.blogspot.com/2013/11/opening-two-windows-for-one-webdriver.html. The third option in this article talks about how to open two windows associated with one WebDriver instance. Then you can use switchTo() to switch between the windows.

vimal chand

unread,
Jul 17, 2015, 10:53:40 PM7/17/15
to webd...@googlegroups.com
HI Darrell,

Thanks for the reply. as you stated in the second statement, I have a parent window , which has a link clicking on which will open a new non modal window . The second window by default has a alert which will take a value from the parent window text box (say we have entered abc). So once we click on the link in parent window, it opens a second non modal window which shows a alert containing the text abc. Hope this helps in understanding the actual situation. Also, the window handles solution given in your blog does not help because the handle is always one.I m stuck here.Please help. Please look into the following link for the exact business situation.

http://seleniumforum.forumotion.net/t2837-selenium-webdriver-click-operation#6531

darrell

unread,
Jul 26, 2015, 6:17:08 PM7/26/15
to webdriver, vcjpo...@gmail.com
Don't know if this would work but I would code a method which takes as input the locator for the link you click to open the new window and returns a Selenium window handle. See http://darrellgrainger.blogspot.com/2012/04/how-to-find-popup-window-if-it-does-not.html for an example. Then the code would be:
  1. call the method to open the new window
  2. switch to the new window
  3. handle the alert
You probably need to handle the alert before you do anything else or it would throw an unhandled alert exception. This would be my first attempt. My gut tells me that before you can switch to the new window it throws the exception for the unhandled alert. So maybe I need to handle the alert immediately after I click the link (see the line in the method with link.click()). Then I can return the handle to the new window.

If neither of those ideas work you'll have to figure out why it fails and how you can change the order of operation to handle things correctly. I've never had to deal with this edge case. So I don't have a set answer.

vimal chand

unread,
Jul 29, 2015, 11:35:22 PM7/29/15
to webdriver, darrell....@gmail.com
HI Darrell,

Thank you very much for the reply. I will try the solution given by you. But i have tried the window handles already which always gives me the size as 1. I don't want to comment without using your solution. I will keep you posted once i test it.
Reply all
Reply to author
Forward
0 new messages