find element on child window

77 views
Skip to first unread message

Chandan Narang

unread,
Jul 27, 2016, 3:41:14 AM7/27/16
to Selenium Users
Hi Friends,

After opening a certain website, message box/child window appears which demands for user name and password. i am not able to view page source of that child window. I need it to find element and send keys.Please help me and let me know if you need more information.

Thanks,
Chandan 

Chandan Narang

unread,
Jul 27, 2016, 6:20:48 AM7/27/16
to Selenium Users
I need to find element on child window.How should i find it as i am not able to view page source of child window.

Nagarjuna Madineni

unread,
Jul 27, 2016, 8:13:46 AM7/27/16
to Selenium Users
Hi Chandan,

Can you try this...

http://UserName:Pass...@Example.com

Hope it will handle the authentication username and password  alerts

Andrew Jervis

unread,
Jul 27, 2016, 10:40:13 AM7/27/16
to Selenium Users
Chandang

Your question is difficult to understand: Below is code for opening the Mercury web tours website and entering name and password which may help

(Spreadsheet test1 is a simple list of cities eg Paris, Zurich, Seattle)

**********************

package Trainingpack;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.io.*;
import jxl.Workbook;

//Opens Mercury Tours and cycles through 3 screens and cycles through spreadsheet

public class wiki6 {

      public static void main(String[] args) throws Exception {
     
            File src=new File("C:\\CA\\test1.xls");
                               
            WebDriver driver = new FirefoxDriver();
           
            int j = 3;
           
            do
                 
            {
           
                  driver.manage().window().maximize();
           
                  driver.get("http://www.newtours.demoaut.com/");
           
                  driver.findElement(By.name("userName")).clear();
           
                  driver.findElement(By.name("userName")).sendKeys(new String[] {"tutorial"});
           
                  driver.findElement(By.name("password")).clear();
           
                  driver.findElement(By.name("password")).sendKeys (new String[] {util.PASSWD});
                 
                  driver.findElement(By.name("login")).click();
                 
                  //Get workbook
                 
                  Workbook wb=Workbook.getWorkbook(src);
                 
                  String str1 = wb.getSheet(0).getCell(0,j).getContents();
                 
                  System.out.println (str1);
                 
                  driver.findElement(By.name("fromPort")).sendKeys(new String[] {str1});
                 
                  driver.findElement(By.name("toPort")).sendKeys(new String[] {"Paris"});
                 
                  driver.findElement(By.name("toDay")).sendKeys(new String[] {"26"});
                 
                  Thread.sleep(2000);
                 
                  driver.findElement(By.name("findFlights")).click();
                 
                  Thread.sleep(2000);
           
                  driver.findElement(By.name("reserveFlights")).click();
                 
                  Thread.sleep(2000);
                 
                  driver.findElement(By.name("passFirst0")).sendKeys(new String[] {"Andrew"});
                 
                  Thread.sleep(2000);
                 
                  driver.findElement(By.name("passLast0")).sendKeys(new String[] {"Jones"});
                 
                  Thread.sleep(2000);
                 
                  driver.findElement(By.name("creditnumber")).sendKeys(new String[] {"12345678"});
                 
                  Thread.sleep(2000);            
                 
                  driver.findElement(By.name("buyFlights")).click();
                                                    
                  Thread.sleep(2000);
                
                  Thread.sleep(2000);                
                 
                  j=j-1;
                 
            }while(j>0);
           
            //driver.close();
           
      }

}

Chandan Narang

unread,
Jul 28, 2016, 5:45:31 AM7/28/16
to Selenium Users
Thanks Naga,

I accessed the url but it is giving following message

"This domain is established to be used for illustrative examples in documents. You may use this domain in examples without prior coordination or asking for permission."


On Wednesday, July 27, 2016 at 5:43:46 PM UTC+5:30, Nagarjuna Madineni wrote:
Hi Chandan,

Can you try this...

Chandan Narang

unread,
Jul 28, 2016, 5:45:56 AM7/28/16
to Selenium Users
Thank you so much Andrew for reply.Actually my problem is that to detect elements say by name i need to see the attributes from page source but i am unable to view page source of child window/pop up that appears.

For example:

Following code:

 driver.findElement(By.name("userName")).clear();

To see Name attribute i need to view the page source but  right clicking on child window is disabled so how can i view the attributes :(

I hope i am able to explain it well now 

thanks

Andrew Jervis

unread,
Jul 28, 2016, 11:48:00 AM7/28/16
to Selenium Users
Chandan

I think I understand your problem now which is to see Name attribute you need to view the page source but  right clicking on child window is disabled so you cannot see the attributes

Try the following
  1.   Go to View->Developer->Page Source in Chrome and you get the page source code or
  2. You can press F12 to launch the developer tools. And then you can use the inspect element to check whichever element you are interested in
Regards, Andrew Jervis

Sampath S

unread,
Jul 29, 2016, 8:38:32 AM7/29/16
to Selenium Users
You can try as Andrew suggested,. If you still having problem, simply you can make use if FireBug/Selenium IDE for attributes identification.
Reply all
Reply to author
Forward
0 new messages