Showing posts from May, 2014

Handle Sharepoint HTTP basic window authentication - using selenium webdriver java

import org.openqa.selenium.Alert;
import java.awt.*; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent;
// Switch to alert window. Alert authenticationWindow = driver.switchTo().alert();
// Type the username/email. authenticationWindow.sendKeys("<username/email address>");
// Shift cursor focus to password input text field. Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_TAB);
// Type the password in password field. [ Selenium does not know at this point that the cursor focus is shifted, so calling Alert class instance sendKeys() will cause password to be typed in username field. So, we are copying the password first to windows clipboard and then pasting it directly into the password field using  Robot class instance ] StringSelection stringSelection = new StringSelection("<user password>"); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection,null); robot.keyPress(KeyEvent.VK_CONTROL); robot.key…