Like us on Facebook

LightBlog

August 28, 2013

Handling HTTPS sites Or Handling Security Certificate Errors using Selenium WebDriver

August 28, 2013 1
Selenium webdriver is used to automate web applications. Web applications generally starts with http://www.example.com......But some websites like internal websites or banking or secured web sites will starts with https://www.example.com. 

Below is one of the approach to handle https site while you are running from InternetExplorer.




Here we need to click the second option to go in to website.

Here we are taking help of Java script to click the second link 


Below is the code for handling https site..


===============================================
package scripts;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class HttpsTest {
WebDriver driver;
@Test
public void httpsTest() throws Exception {
driver.get("https://esupport.satyam.com/main.aspx");
                //Java script to click the link
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
Thread.sleep(5000);
              //assert the title of the page
Assert.assertEquals(driver.getTitle(), "Welcome to Tech Mahindra Universe");
System.out.println("asssert successfull");
Thread.sleep(5000);
}
@BeforeTest
public void beforeTest() {
//launch Internet explorer
System.setProperty("webdriver.ie.driver", "F:\\Jar\\IEDriverServer.exe");
driver=new InternetExplorerDriver();
driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}

@AfterTest
public void afterTest() {
driver.close();
driver.quit();
}

}
==============================================================
Hope this post will be useful......

August 4, 2013

Get Values from Dropdown (Birthday field in Gmail registration )

August 04, 2013 2
Below is the sample script to get  values or options from a dropdown.

Below is the image of Birth Month dropdown





The Birth Month field is not a Drop down. If you want to get all the values from dropdown first we need to click on the arrow mark and then we can get all the values of dropdown.

Here in the below example..first click on the drop down arrow then all the elements (Month options) will be visible and then you can get all the values of dropdown.
===============================================================
package one;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Gmail_Reg {
public WebDriver driver;

@Before
public void setUp() throws Exception {
//Specify the browser
driver=new FirefoxDriver();
//declare globally wait
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//maximize the window
driver.manage().window().maximize();
}

@After
public void tearDown() throws Exception {
//close the browser
driver.quit();
}

@Test
public void testGmail_Reg() throws Exception {


driver.get("https://accounts.google.com/SignUp");
//click on the arrow mark
driver.findElement(By.xpath("//label[@id='month-label']/span/div/div")).click();
//get all the vlaues of dropdown
List x=driver.findElements(By.xpath("//div[@class='goog-menu goog-menu-vertical']/div"));
System.out.println("Size of the dropdown : "+x.size());
//print dropdown options
for (int i = 0; i < x.size(); i++) {
System.out.println(x.get(i).getText());
}
Thread.sleep(5000);

}

}
=============================================================

Output:
Size of the dropdown : 12
January
February
March
April
May
June
July
August
September
October
November
December

===================================================================