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

  • Where is the snapshot and the html as you've mentioned – demouser123 Jul 9 '15 at 8:56
  • <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> – Aman Sharma Jul 9 '15 at 8:57
  • Sorry i miss image and code , both uploaded now please have a look. – Aman Sharma Jul 9 '15 at 8:58
  • i try protected mode off enable URL on popup window try to open window on with URL but nothing works. – Aman Sharma Jul 9 '15 at 9:05
  • If you are now able to switch to the new page, are you able to just View Source through the context menu to get the ID or Name and then SelectByText()? – Lyndon Vrooman Jul 10 '15 at 13:18
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?

  • 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 9 '15 at 9:34
  • stackoverflow.com/questions/420542/… try [Check David Eison's answer] – demouser123 Jul 9 '15 at 9: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 9 '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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.