3

I am working on automation of a website using Selenium and C#, but I am stuck in a situation where on a button click a new webpage dialog opens and on that web page dialog we have to select some value and click on save button.

Problem is I am unable to switch to that webpage dialog and even F12 window not working on that webpage dialog this website is only working on IE so no other option. Please help me.

Here is post screenshot of webpage dialog and HTML code of button which open that dialog box.

<INPUT onclick=showClose(); id=ucTicketDetail1_btnClose 
title=Close style="BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px;
BORDER-BOTTOM-WIDTH: 0px; BORDER-TOP-WIDTH: 0px"
src="../images/tasks.gif" type=image name=ucTicketDetail1$btnClose> 

enter image description here

Niels van Reijmersdal
  • 32,520
  • 4
  • 57
  • 124
Aman Sharma
  • 151
  • 1
  • 6

2 Answers2

1

You need to switch to the window and then perform whatever you are going to perform on the child window.

Though I am not familiar with C#, this is how I would try:

btn1=driver.find_element_by_id('ucTicketDetail1_btnClose') 
#guessing this is the id of button that triggers the webpage dialog to open

btn1.click()

newWindow=driver.window_handles[1]

#switch to new window
driver.switch_to.window(newWindow)

#get the element id you want to interact
element1=driver.find_element_by_id(idofElementyouwanttointeract)

#use select for dropdowns
Select s1=new Select(element1)

#select the dropdown option using the text
s1.select_by_visible_text('text')

#click on save button
savebtn2=driver.find_element_by_id(idofSaveButton).click()

#return to original window
driver.switch_to.default_content

This is in Python, but you can use this to convert it into C#. A possible solution is also provided here :

How can I switch to new window using webdriver?

demouser123
  • 3,532
  • 5
  • 28
  • 40
  • Thanks for the answer , I am now able to switch to new window but i am not able to find locator of drop down text area and button of new window as F12 is not working on popup window in IE 11. – Aman Sharma Jul 09 '15 at 09:34
  • http://stackoverflow.com/questions/420542/using-ie-dev-toolbar-on-a-pop-up-windowed-web-app try [Check David Eison's answer] – demouser123 Jul 09 '15 at 09:39
  • Yes i already read this and apply this in IE , This enable URL bar but still F12 is not working . I think this popup is model window but i don't know how to handle this. – Aman Sharma Jul 09 '15 at 10:35
0

To interact with elements in new window you have to switch you driver focus to new window, you can do it with the help of

driver.switch.window("Title of window")

And then try to find out the dropdown element in the window

Note: If title of window does not work in your case, there are other ways to find out the window. For example finding out number of windows open then switch to window totalWindows-1

demouser123
  • 3,532
  • 5
  • 28
  • 40
Jeevan Bhushetty
  • 1,516
  • 12
  • 21