How to scroll to bottom/down of page in Selenium ?

@Test //(enabled=false)
public void ScrolltoBottomonPage() throws Exception
{
driver.get("
http://seleniumsubbu.blogspot.in/");
Thread.sleep(5000);
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,5000)");
// OR
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,1000)", "");
// OR
jse.executeScript("scroll(0, 250)");
}
@Test //Page Scroll "DOWN" using Selenium WebDriver
public void ScrollDown() throws Exception
{
driver.get("http://seleniumsubbu.blogspot.in/");
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 950)"); // Y value is scroll down
Thread.sleep(5000);
}
@Test //Page
 Scroll "UP" using Selenium WebDriver
public void ScrollTop() throws Exception

{
driver.get("
http://seleniumsubbu.blogspot.in/");
Thread.sleep(3000);
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(750, 0)"); 
// X value is scroll up
}

Print all COOKIES :-

@Test
public void CookiesinWebsite() throws Exception
{
driver.get("
http://seleniumsubbu.blogspot.in/
");
// Now set the cookie. This one's valid for the entire domain
Cookie cookie = new Cookie("key", "value");
driver.manage().addCookie(cookie);
// And now output all the available cookies for the current URL
Set<Cookie> allCookies = driver.manage().getCookies();
for (Cookie loadedCookie : allCookies)

 {
System.out.println(String.format("%s -> %s", loadedCookie.getName(), loadedCookie.getValue()));
}
}

Number of frames on a page :-

List<WebElement>framesList=driver.findElements(By.xpath("//iframe"));
intnumOfFrames=frameList.size();

Createandwritedataintotxtfile

Filef=newFile(“/home/chinna/techlearn/testdata.txt”); //LInux path
FileWriterfw=newFileWriter(f);
BufferedWriterbw=newBufferedWriter(fw);
bw.write(“Techlearn”);
bw.newLine();
bw.write(“Selenium”);
bw.newLine();
bw.write(“Linux”);
bw.close();
fw.close();

Printdatafromnotepad(txtfile):-

Filef=newFile(“/home/Subbu/Selenium/WebDriver.txt”); //Linux path
FileReaderfr=newFileReader(f);
BufferedReaderbr=newBufferedReader(fr);
Stringstr;
while((str=br.readLine())!=null)
{
System.out.println(str);
}

Create Excel file :-

FileOutputStream fo=newFileOutputStream(“Pathtocreatexlsfile”);
WritableWorkbookwb=Workbook.createWorkbook(fo);
WritableSheetws=wb.createSheet(“Results”,0);
Labelun=newLabel(0,0,”Username”);
ws.addCell(un);
wb.write();
wb.close();

Take data frome xcel (xls)file:-

FileInputStream fi=newFileInputStream(“Pathoftheexcelfile”);
Workbookw=Workbook.getWorkbook(fi);
Sheets=w.getSheet(0);
s.getCell(columnID,rowID).getContents())
ex:s.getCell(0,1).getContents();

How to create log file using Log4j in SeleniumWebdriver with Java

  public class Log4j
.{
  public static void main(String[] args) throws Exception
 {
  
Logger logger= Logger.getLogger("LogLearning");
  PropertyConfigurator.configure("Log4j.properties");

 
 System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
  WebDriver driver= new FirefoxDriver();
  public WebDriver driver;
  
logger.info("Firefox Opened");
  driver.manage().window().maximize();
 
 logger.info("Brows maximized");
  driver.get("http://seleniumsubbu.blogspot.in/");
 
 logger.info("Website is launched");
  }
 

AutoIT :-

@Test
public void FileAttachement() throws Exception
{
driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
driver.get("
http://seleniumsubbu.blogspot.in/");
driver.findElement(By.id("edit-submitted-uploadfile-upload")).click();
Runtime.getRuntime().exec("C:\\Users\\chinna\\Desktop\\AutoIT\\Fileupload.exe");
}

Sikuli :-

public class Gmail_Upload
{
    public WebDriver driver;
    public Screen s;
@Test // SIKULI SCRIPT for  upload file
public void FileAttachement() throws Exception
{
driver.get("
http://seleniumsubbu.blogspot.in/");
driver.findElement(By.id("edit-submitted-uploadfile-upload")).click();
s.click("/home/chinna/lib/Sikuli/techlearn.in.png");        // (Or) s.click("Image")
driver.findElement(By.id("
edit-submitted-uploadfile-upload-button--4")).click();
}
@BeforeTest
 public void beforeTest()

{
driver=new FirefoxDriver();
 s=new Screen();

}

Handle Popup :-

We have to navigate to the popup windows
driver.switchTo().window(“WindowName”);
To navigate from Popup window to main window
driver.switchTo().window(“MainWindowName”);
Below approach to handle Dynamically changing popup windows
Set<String> window1= driver.getWindowHandles();
Object 
s[]=window1.toArray();
driver.switchTo().window(
s[1].toString());
Handle multiple popups windows

driver.getWindowHandles();

How to insert text in text field of model window using selenium webdriver ?

We have to navigateto Alert or Confirmation windows
driver.switchTo().alert();                                                   
To click on "OK"  or "Cancel" on Alertor Confirmation 
driver.switchTo().alert().accept();—ToclickOK                   
driver.switchTo().alert().dismiss();—ToclickCancel          
@Test
public void Entertext()throws Exception
{
driver.get("
http://seleniumsubbu.blogspot.in/");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id='node-223']/div/div[1]/div/div/button")).click();
Alert 
alert = driver.switchTo().alert();
alert.sendKeys("The value that you wish to enter");
alert.accept();

}          
                                                                                    

How to handle SSL Certificates in selenium webdriver in Chrome

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
 
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 
 System.setProperty("webdriver.chrome.driver", "/home/chinna/lib/chromedriver");// Your chromedriver path.
 driver = new ChromeDriver(
capabilities);
 driver.get("
http://seleniumsubbu.blogspot.in/"); 

How to handle SSL Certificates in selenium webdriver in firefox

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver= new FirefoxDriver(
capabilities);
driver.get("
http://seleniumsubbu.blogspot.in/");

How to use robot class in selenium webdriver

 Robot rbt= new Robot();                        // Create object of Robot class
  rbt.keyPress(KeyEvent.VK_ENTER);      // Press Enter
 
 rbt.keyRelease(KeyEvent.VK_ENTER); 
 // Release Enter

How to press Keyboard Function keys, Letters, and Numbers using Selenium Webdriver ?

@Test
      public void KeyboardactionNewPrivateWindow() throws AWTException
{
          driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
          driver.get("
http://seleniumsubbu.blogspot.in/");
          Actions act=new Actions(driver);
          
act.contextClick(driver.findElement(By.linkText("seleniumsubbu"))).perform();  // Right click action
          driver.findElement(By.linkText("seleniumsubbu")).sendKeys(Keys.ARROW_DOWN);  // Arrow down 3 times
          driver.findElement(By.linkText("
seleniumsubbu")).sendKeys(Keys.ARROW_DOWN);
          driver.findElement(By.linkText("
seleniumsubbu")).sendKeys(Keys.ARROW_DOWN);
          driver.findElement(By.linkText("seleniumsubbu")).sendKeys(Keys.ENTER);  // Click on Enter button .
      } 

Keyboard interactions or Keyboard Shortcuts using Selenum Webdriver ?

driver.get("http://seleniumsubbu.blogspot.in/");
String selectalltext = Keys.chord(Keys.CONTROL, "a"); // select all text in techlearn.in home page
driver.findElement(By.linkText("TechLearn.in")).sendKeys(
selectalltext);
                      
                                                                 

                                                   {Or }
driver.findElement(By.linkText("
http://seleniumsubbu.blogspot.in/")).sendKeys(Keys.CONTROL, "t");
driver.navigate().to("
http://seleniumsubbu.blogspot.in/");
driver.findElement(By.linkText("Personal Website")).sendKeys(
Keys.CONTROL, "n");
Set<String> window1=driver.getWindowHandles();
Object s[]=window1.toArray();
driver.switchTo().window(s[1].toString());
driver.get("
http://seleniumsubbu.blogspot.in/
"); 

Fullpage Screenshot for Firefox and Chrome using Selenium WebDriver ?

public class TechLearn
 {
public WebDriver driver;
public Selenium selenium;
public void Screenshot() throws Exception
{
DateFormat dateFormat = new SimpleDateFormat("yyyy_MMM_dd HH_mm_ss");
Date date = new Date();
String time=dateFormat.format(date);
System.out.println(time);
File f = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(
f, new File("/home/chinna/Desktop/TechLearn"+time+".png"));// Linux machinepath
//
FileUtils.copyFile(f, new File("F:\\Workspace\\ seleniumsubbu "+time+".png")); // for windowsmatchine path
}
@Test // Print Full Screenshot
public void PrintScreenShot() throws Exception{
driver.get("
http://seleniumsubbu.blogspot.in/");
Screenshot();

}                                                                                                                                                                                     

Double click :-

@Test
public void Doubleclick() throws Exception

{
driver.get("
http://seleniumsubbu.blogspot.in/");
Thread.sleep(3000);
Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.xpath("//*[@id='node-235']/div/div[1]/div/div/button"))).doubleClick().perform();

}

How to perform MOUSEHOVER function in Selenium WebDriver using Java Selenium WebDriver

@Test
public void mousehover()
{
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("
http://seleniumsubbu.blogspot.in/");

WebElement element = driver.findElement(By.id("menu-328-1"));
Actions act = new Actions(driver);
act.moveToElement(element).build().perform();
driver.findElement(By.linkText("Selenium Scripts")).
click();

}            
                                  
 

How to right click on a link and select an option using Selenium WebDriver

@Test
public void RightClick() throws Exception

{
driver.get("
http://seleniumsubbu.blogspot.in/");

Thread.sleep(3000);
Actions act=new Actions(driver);
act.contextClick(driver.findElement(By.linkText("Quiz"))).perform();

}

Drag and Drop :-

Actions act=newActions(driver);
WebElement source=driver.findElement(By.xpath(“-----”));
WebElement target=driver.findElement(By.xpath(“-----”));
act.
dragAndDrop(source,target).perform();

Current page URL :-

driver.getCurrentUrl();

Webdiver BackedSelenium :-

Selenium = new webDriverBackedSelenium(driver, "http://seleniumsubbu.blogspot.in/ ");

Title :-

driver.getTitle();

Window Maximize :-

driver.manage().window().maximize();

Synchronization :-

     Thread.sleep(9000);
 selenium.
waitForPageToLoad("9000");
         selenium.setTimeout("90000");
         WebDriverWaitwait=newWebDriverWait(driver,9);
wait.
until(ExpectedConditions.elementToBeClickable(By.id("element-id")));
 driver.
manage().timeouts().implicitlyWait(9,TimeUnit.SECONDS);
         driver.manage().timeouts().pageLoadTimeout(9,TimeUnit.SECONDS);
         Wait<WebDriver>  wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.polingEvery(5, SECONDS)
.ignoring(NoSuchElemntException.clas);

         robot.delay(1000);

How to send text,select Radio button,Dropdown list & particular date from a date picker in Selenium web driver?

         ID
           driver.findElement(By.
id("gbqfq")).sendKeys("SeleniumSubbu");
         Name
             driver.findElement(By.
name("q")).sendKeys("SeleniumSubbu");
         CSS(Cascadestylesheet)
             driver.findElement(By.
cssSelector("Register")).click();
       XPATH
             Relativexpath
                       driver.findElement(By.
xpath("(//input[@id='gender'])[2]")).click();
             Absolutexpath
                       driver.findElement(By.
xpath("(//div[1]/div[2]/div[1]/div[2]/button[1]")).click();
         Classname
      driver.findElements(By.
className("SeleniumSubbu "));
         TagName
      driver.findElement(By.
tagName("SeleniumSubbu "));
         LinkText
      driver.findElement(By.
linkText("Sign-in")).click();
         PartialLinkText
      driver.findElement(By.
partialLinkText("selenium"));
     Close :- 
      driver.close();
     Quit :- 
      driver.quit();
     Clear :- 
      driver.findElement(By.id("edit-submitted-first-name-")).clear();
     Get :- 
      driver.get("http://seleniumsubbu.blogspot.in/ ");
      Type :- 
      driver.findElement(By.id("edit-submitted-first-name-")).sendKeys("SeleniumSubbu");