Showing posts with label frame. Show all posts
Showing posts with label frame. Show all posts

Tuesday, June 3, 2014

Switch to window then frame then again switch back to frame and window. (complex example)

Note- Please do the manual steps first and see how the flow going then try with the script.
Manual Steps-
1) open google
2) type in search box 'times of india'
3) click on 1st link of 'times of india'
4) click on 'click here to go to timesofindia.com'
5) click on 'Login' button (which is in the top just beside the LogIn with Facebook)
6) click on facebook
7) check the checkbox in facebook page and click on cancle
8) then close the frame (which has 3 options facebook, twitter and your email)
9) click on india in main page.
10) close the browser.

import java.util.Iterator;
import java.util.concurrent.TimeUnit;

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


public class TimesOfIndia {
    public static void main(String[] args) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);
        driver.get("https://www.google.co.in/"); //open google
        driver.findElement(By.id("gbqfq")).sendKeys("times of india"); //type in search box 'times of india'
        driver.findElement(By.xpath("//span[text()='times of india']")).click(); //click on 1st link of 'times of india'
        driver.findElement(By.xpath("//div[div[div[div[cite[b[text()='indiatimes']]]]]]//a[text()='The ']")).click(); //click on 'click here to go to timesofindia.com'
        driver.findElement(By.linkText("Log In")).click(); //click on 'Login' button
        driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='signupsso']"))); //now switch to login frame which has 3 options facebook, twitter and your email
        driver.findElement(By.id("fb")).click(); //click on facebook which will open in new window
        Iterator<String> it = driver.getWindowHandles().iterator();// get the address of all the windows
        String times = it.next();
        String fb = it.next();
        driver.switchTo().window(fb); // switch to facebook window
        driver.findElement(By.xpath("//input[@type='checkbox']")).click(); //check the checkbox in facebook window
        driver.findElement(By.xpath("//input[@value='Cancel']")).click(); //click on cancle button in facebook window
        driver.switchTo().window(times); //switch back to main window
        driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='signupsso']"))); //again switch to login frame which has 3 options facebook, twitter and your email
        Thread.sleep(2000);
        driver.findElement(By.xpath("//img[@src='/photo/11509366.cms']")).click(); // click on cross sign to close frame
        Thread.sleep(2000);
        driver.switchTo().defaultContent(); //switch back to main page
        driver.findElement(By.xpath("//div[ul[script[text()='sectionid=4719157']]]//a[@href='/india/indiaarticlelist/-2128936835.cms']")).click(); //click on india
        driver.close();
    }

}

Wednesday, May 21, 2014

how to handle frame ?



import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Frame {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();
//driver.manage().window().maximize();
driver.navigate().to("https://www.zoho.com/crm/lp/login.html");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement ifr = driver.findElement(By.xpath("//iframe[contains(@src,'accounts.zoho.com/login')]"));
driver.switchTo().frame(ifr);
driver.findElement(By.id("lid")).sendKeys("venkyin.2218@gmail.com");
driver.findElement(By.id("pwd")).sendKeys("Venkatesh");
driver.findElement(By.id("submit_but")).click();
driver.switchTo().defaultContent();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@id='tab_Campaigns']")));
driver.findElement(By.xpath("//a[@id='tab_Campaigns']")).click();
driver.findElement(By.xpath("//tr[td[3][a[text()='Venky']]]")).click();
driver.findElement(By.linkText("Add Existing Leads")).click();
driver.findElement(By.name("search")).click();
driver.close();
}
}

Tuesday, May 20, 2014

How to type in next line in a text box ?

Note- use \n to move the control to next line.
ex-

import java.util.concurrent.TimeUnit;

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

public class TextBox {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://selenium-makeiteasy.blogspot.in/2014/05/if-any-textbox-is-disabled-then-how-to.html");
       
        WebElement textBox = driver.findElement(By.xpath("//iframe[@id='comment-editor']"));
        driver.switchTo().frame(textBox);
       
       
        WebElement comment = driver.findElement(By.xpath("//textarea[@id='commentBodyField']"));
        comment.sendKeys("good \n nice");
    }
}