How can take screenshot of new tab once its loaded completly in selenium - selenium

#Test
public void testHeaderlinks() throws IOException {
homePage=new HomePage();
homePage.ClickmenuHolidays();
homePage.Clickmenuattraction();
homePage.Clickmenuhotdeal();
String originalHandle = driver.getWindowHandle();
for(String handle : driver.getWindowHandles()) {
if (!handle.equals(originalHandle)) {
driver.switchTo().window(handle);
driver.close();
}
}
driver.switchTo().window(originalHandle);
}
public static void Takescreenshot(String filename) throws IOException {
File file= ((TakesScreenshot))driver.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file,new File("C:\\Users\\User\\Desktop\\POMMabuhayFinal\\src\\main\\java\\Screnshots\\"+filename+".jpg"));
}
In my code i am click hyperlinks in new tab and close those tabs (closing all tabs after all hyperlinks clicks)
My question is how can i take screenshot of opened tabs( i wanna take all new tabs which are open)

Use WebDriverWait to wait for tab/page load and then call your Takescreenshot method while you iterate tabs
#Test
public void testHeaderlinks() throws IOException {
homePage=new HomePage();
homePage.ClickmenuHolidays();
homePage.Clickmenuattraction();
homePage.Clickmenuhotdeal();
String originalHandle = driver.getWindowHandle();
int count = 1;
for(String handle : driver.getWindowHandles()) {
if (!handle.equals(originalHandle)) {
// Initialize WebDriverWait with 15 secs wait timeout or expected wait timeout
WebDriverWait wait = new WebDriverWait(myDriver, 15);
// Wait for page to load
wait.until(webDriver -> ((JavascriptExecutor) myDriver).executeScript("return document.readyState").toString().equals("complete"));
driver.switchTo().window(handle);
// Take screenshot of your current tab
Takescreenshot("tabImage" + String.valueOf(count)) // You can use your own imageName
driver.close();
count++;
}
}
driver.switchTo().window(originalHandle);
}
public static void Takescreenshot(String filename) throws IOException {
File file= ((TakesScreenshot))driver.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file,new File("C:\\Users\\User\\Desktop\\POMMabuhayFinal\\src\\main\\java\\Screnshots\\"+filename+".jpg"));
}

Please Try this
public void TakeScreenShot()
{
try
{
string text = AppDomain.CurrentDomain.BaseDirectory + "\\screenshots\\";
if (!Directory.Exists(text))
{
Directory.CreateDirectory(text);
}
if (Directory.Exists(text))
{
string text2 = text + XYZ+ ".jpeg";
if (File.Exists(text2))
{
File.Delete(text2);
}
((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(text2, ScreenshotImageFormat.Jpeg);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

Related

Extent Report in Jenkins is displaying blank icon for attached screenshots

I have generated a runnable jar of my project, and running it on other machine through jenkins.
Jar file executing successfully and generating extent report also,
but there is a blank icon on the place of screenshots.
I have searched on google but did not find any relevant solution to solve my problem.
I am using Intellij IDE and opening the extent report by using the option of "Open in Browser".
When there are more than two screenshots attached(like in above case) with the extent report, it is showing blank icon and showing error when opening the image in new tab.
(When opening the extent report by going into the folder where it is actually saved in the system, it is working as expected).
My code:
#BeforeTest
public void setExtent() {
extent = new ExtentReports(System.getProperty("user.dir")+ "/test-output/Login.html", true);
System.out.println("KKKKKKK");
extentTest = extent.startTest("Start the Execution");
extent.addSystemInfo("Host Name", "Live Contract");
extent.addSystemInfo("User Name", "Shivam Goyal");
extent.addSystemInfo("Environment", "Develop");
extentTest.log(LogStatus.INFO, "Test Execution started");
}
public static String getScreenshot(WebDriver driver, String screenshotName) {
String dateName = new SimpleDateFormat("ddMMyyyyhhmmss").format(new Date());
TakesScreenshot ts = (TakesScreenshot) driver;
File src = ts.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+ "/test-output/"+ screenshotName + dateName + ".png";
File destination = new File(path);
try {
FileUtils.copyFile(src, destination);
}
catch(IOException e){
System.out.println("Capture Failed" +e.getMessage());
}
return path;
}
#Test
public void openURL() throws IOException, InterruptedException, HeadlessException, UnsupportedFlavorException {
System.out.println("test openWeb");
extentTest = extent.startTest("LC1_1.1 - Verify the Login Panel of \"Berater\".");
try {
//Accept All cookies
driver.findElement(By.className(property.getProperty("LiveContractCookies"))).click();
//Test case LC1_1.1 Open the given URL in Browser (Aufruf der entsprechenden URL im Browser)
boolean Homescreen = driver.findElement(By.name(property.getProperty("BeraterLoginPanelName1"))).isDisplayed();
Thread.sleep(3000);
Assert.assertTrue(Homescreen);
} catch (NoSuchElementException e) {
e.printStackTrace();
}
}
#Test
public void checkEntryFields() throws InterruptedException {
extentTest = extent.startTest("LC1_1.2 - Verify the Entry fields on Berater's login panel");
try {
driver.findElement(By.className(property.getProperty("LiveContractCookies"))).click();
WebElement username = driver.findElement(By.name(property.getProperty("username_fieldName")));
WebElement password = driver.findElement(By.name(property.getProperty("password_fieldName")));
username.click();
username.sendKeys("Test123");
password.click();
password.sendKeys("9876554");
Thread.sleep(1000);
System.out.println(username.getText());
String usnm = username.getAttribute("value");
String pass = password.getAttribute("value");
System.out.println("Something happening");
Assert.assertEquals("Test123", usnm);
Assert.assertEquals("98765", pass);
}
catch(Exception e){
e.printStackTrace();
}
}
#AfterMethod
public void tearDown(ITestResult result) {
if(result.getStatus() == ITestResult.FAILURE){
extentTest.log(LogStatus.FAIL, "Test Case Failed is" +result.getName());
extentTest.log(LogStatus.FAIL, "Test Case Failed is" +result.getThrowable());
String screenshotPath = Login.getScreenshot(driver, result.getName());
extentTest.log(LogStatus.FAIL, extentTest.addScreenCapture(screenshotPath));
}
else if(result.getStatus() == ITestResult.SKIP){
extentTest.log(LogStatus.SKIP, "Test Case Skipped is "+result.getName());
}
else if(result.getStatus() == ITestResult.SUCCESS){
extentTest.log(LogStatus.PASS, "Test Case Passed is "+result.getName());
}
extent.endTest(extentTest);
//extent.flush();
driver.quit();
//tempDriver.quit();
//tempDriver.quit();
}
#AfterTest
public void endReport() {
try{
extent.flush();
}
catch(Exception e){
e.getMessage();
}
//extent.close();
}

give delay in showing the controls

I would like to add the button controls in a timely manner.
That means, after the shell opened, it should start placing the buttons one by one
in a 1 second delay. I wrote the program,however it does not work. all the buttons
are visible only after all the controls are placed. Some kind of refresh issue I guess.
Following is my code.
public class DelayAddingComponentsExample {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(200, 200);
shell.setLayout(new FillLayout(SWT.VERTICAL));
addAutomatically(shell);
// removeAutomatically(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void addAutomatically(final Shell shell) {
for (int i = 0; i < 5; i++) {
final Button button = new Button(shell, SWT.NONE);
button.setText("Button" + i);
button.setVisible(false);
}
shell.getDisplay().timerExec(0, new Runnable() {
#Override
public void run() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(500);
final Button button = new Button(shell, SWT.NONE);
button.setText("Button" + i);
button.setVisible(true);
shell.pack();
shell.layout(true);
shell.redraw();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
public static void removeAutomatically(final Shell shell) {
for (int i = 0; i < 5; i++) {
final Button button = new Button(shell, SWT.NONE);
button.setText("Button" + i);
shell.layout(true);
}
shell.getDisplay().timerExec(0, new Runnable() {
#Override
public void run() {
Control[] controls = shell.getChildren();
for (Control control : controls) {
try {
Thread.sleep(500);
control.dispose();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
}
The Runnable given to timerExec runs in the UI thread. So the Thread.sleep calls you are making are blocking the UI thread - it is vital that you never block this thread. Never call Thread.sleep in the UI thread.
You must do each step using a separate timeExec call and use the delay parameter of the timerExec call to specify how long to wait.
So
shell.getDisplay().timerExec(500, new Runnable() {
#Override
public void run()
{
// TODO code for the first button only
// Schedule next update
shell.getDisplay().timerExec(500, .... code for second button);
}
});
Runs the Runnable after 500 millseconds, the Runnable should just do the first step and then call timerExec again to schedule the next step.

Error in extension for webdriver

I'm writing a framework with page object. I have a lot of ajax, so in order to get rid of ugly Thread.sleep(5000), I created an extension method, which waits until an element is visible and clicks on it, otherwise it throws an error. But I suspect that there is an error in my code, because it always thrown an error.
public static void WaitForVisible(this IWebElement element, int timeoutSec = 10)
{
var startTime = DateTime.Now;
while ((DateTime.Now - startTime) > TimeSpan.FromSeconds(timeoutSec))
{
if (element.Displayed)
return;
}
throw new Exception("Element wasn't displayed after '" + timeoutSec + "'!");
}
public static void ClickWithWait(this IWebElement element)
{
WaitForVisible(element);
element.Click();
}
Could you please tell what am I doing wrong?
Please try this method.
WebDriverWait wait = new WebDriverWait(driver, 10);
try {
WebElement element= wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("someid")));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}

TestNG Asserts put under Page Objects are not reflected in the TestNG report for webdriver test

I am working on Java-selenium test framework.
We are calling individual page objects for testing methods viz:
verifyOrderSummary()
These methods sitting inside Page Object will have individual TestNG asserts
Now, when I run my main calling methods / TestNG Tests then, after execution of the test result of the assert is not getting written in the TestNG report.
Kindly advise.
How should I structure my Page Object driven tests, so that- assertings (soft/hard) will get reflected in the final TestNG report.
Many thanks
Hi, Below is one of the key test method( calling various page objects representing various pages):
#Test(dataProvider="BillingDataExcel")
public void dataEntryMethod(String sNo, String sTestCaseName, String sTestDesc, String sAddMedia, String sSupplyVia, String sClock, String sAdvertiser, String sSubtitles, String sBrand, String sPriceModel, String sMarket) throws InterruptedException, IOException {
try{
loginToA5();
navigateToDeliveryDashboard();
softAssert = new SoftAssert();
deliveryLandingPageDataVariant = new DeliveryLandingPageDataVariant(driver);
Thread.sleep(1000);
deliveryLandingPageDataVariant.triggerCreateOrder();
Thread.sleep(1000);
deliveryLandingPageDataVariant.changeCountry(sMarket);
Thread.sleep(1000);
deliveryLandingPageDataVariant.addMedia(sAddMedia, sSupplyVia);
//****XML Driven variant below****
//deliveryLandingPageDataVariant.AddInformation();
deliveryLandingPageDataVariant.AddInformation(sClock,sAdvertiser,sSubtitles,sBrand);
//****XML Driven variant below****
//deliveryLandingPageDataVariant.selectBroadCastDest();
deliveryLandingPageDataVariant.selectBroadCastDest(sNo);
myUtil.TakeSnapShot(driver, "AfterFilling-inData");
deliveryLandingPageDataVariant.submitData();
Thread.sleep(2000);
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
ViewOrderPage viewOrderPage = new ViewOrderPage(driver);
softAssert.assertTrue(viewOrderPage.verifyOrderSummary(sNo,sTestCaseName,myUtil.excelFeederRowCount++));
viewOrderPage.openOrderSummaryAndVerifyDesti(sNo);
/*Below is a Temp hook, before we fix the #After annotation */
driver.close();
driver.quit();
Thread.sleep(1000);
}catch(AssertionError e){
System.out.println("Assertion error or other error -- ");
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}
}
And below is the One of Page Object:
public class ViewOrderPage extends Abstractpage {
XMLDataReader xmlDataReader = new XMLDataReader();
#FindBy(css="#angularHolder > div > div > div.clearfix.pbxs.ng-scope > div > div:nth-child(2) > div > div > div:nth-child(2)")
//#FindBy(xpath=".//*[#id='angularHolder']/div/div/div[1]/div/div[2]/div/div/div[2]")
private WebElement QTYValue;
#FindBy(xpath=".//*[#id='angularHolder']/div/div/div[1]/div/div[3]/div/div[1]/div[2]/span")
private WebElement subTotalValue;
#FindBy(xpath="//button[#data-role='viewReport']")
private WebElement viewOrderSummaryButton;
private final String WAIT_WHEEL_PATH =".//*[#id='angularHolder']/div/div/div[2]/div[2]";
private int i;
String STDCell;
String EXPCell;
String STACell;
private final String DELIVER_TO_STRING=".//*[#id='report']/div/div[2]/div[4]/table/tbody/tr";
public ViewOrderPage(WebDriver driver){
this.driver=driver;
AjaxElementLocatorFactory aFactory= new AjaxElementLocatorFactory(driver, 20);
PageFactory.initElements(aFactory, this);
myWait=new WebDriverWait(driver, 120);
myWait.until(ExpectedConditions.elementToBeClickable(viewOrderSummaryButton));
//myWait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(WAIT_WHEEL_PATH));
}
#SuppressWarnings("finally")
public boolean verifyOrderSummary(String sNo, String sTestCaseName, int feederRowCount) throws Exception{
int subTotal=-1;
int qty=-1;
boolean valueMatched = false;
System.out.println("\n=========================Verify Order Summary Section=================================");
System.out.println("**Quantity =" + getQTY());
System.out.println("**subTotal ="+ getSubTotal());
try {
ExcelUtils.setExcelFile(System.getProperty("user.dir")+"/src/test/java/com/SAPAutomation/testData/BillingData.xlsx","TestResults");
ExcelUtils.setCellData(sNo, feederRowCount, 0);
ExcelUtils.setCellData(sTestCaseName, feederRowCount, 1);
ExcelUtils.setCellData(getQTY(), feederRowCount, 2);
ExcelUtils.setCellData(getSubTotal(), feederRowCount, 3);
System.out.println("Test Results Read: "+ (String.valueOf(ExcelUtils.getCellData(feederRowCount, 4)).toLowerCase()));
if(getSubTotal().toLowerCase().equals("£"+String.valueOf(ExcelUtils.getCellData(feederRowCount, 4)).toLowerCase()+".00")){
valueMatched=true;
System.out.println("\n**Subtotle of "+feederRowCount+" Matched**");
ExcelUtils.setCellData("PASS", feederRowCount, 5);
}else{
ExcelUtils.setCellData("FAIL", feederRowCount, 5);
System.out.println("\n**Subtotle of "+feederRowCount+" didn't match**");
valueMatched=false;
}//end else
// try {
// Assert.assertEquals(getSubTotal(), String.valueOf(ExcelUtils.getCellData(feederRowCount, 4)), "Quantity Matched");
// } catch (Exception e) {
// e.getMessage();
//
// Reporter.log("Assertion error in Verify Order summary:"+ e.getMessage());
// }
} catch (Exception e1) {
e1.printStackTrace();
}finally{
myUtil.takeFieldSnapshot(driver, driver.findElement(By.xpath(".//*[#id='angularHolder']/div/div/div[1]/div")), "OrderSummaryHighlight");
return valueMatched;
}
}
#SuppressWarnings("finally")
private String getQTY(){
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
String QTY = "0";
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try{
return QTY=QTYValue.getText();
}catch(Exception e){
e.getStackTrace();
return QTY;
}
}
private String getSubTotal(){
String subTotal="";
try{
return subTotal = subTotalValue.getText();
}catch (Exception e){
e.getStackTrace();
return subTotal;
}
}
public void openOrderSummaryAndVerifyDesti(String sNo) throws Exception{
String mainWinHande=driver.getWindowHandle();
viewOrderSummaryButton.click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Set<String> handles = driver.getWindowHandles();
for(String handle : handles)
{
if(!mainWinHande.equals(handle))
{
driver.switchTo().window(handle);
String attriAndDestinations[][]=ExcelUtils.getTableArray(System.getProperty("user.dir")+"/src/test/java/com/SAPAutomation/testData/BillingData.xlsx", sNo, myUtil.GLOBAL_MAX_COLUMN_COUNT);
ExcelUtils.setExcelFile(System.getProperty("user.dir")+"/src/test/java/com/SAPAutomation/testData/BillingData.xlsx",sNo);
String destinationCell="";
STDCell="--";
EXPCell="--";
STACell="--";
int broadcasterTableSize= driver.findElements(By.xpath(DELIVER_TO_STRING)).size();
for(i=1;i</*broadcasterTableSize*/attriAndDestinations.length+1;i++){
int xPathDIVCounter=i+2;
//Get Destination
destinationCell=driver.findElement(By.xpath(DELIVER_TO_STRING+"["+xPathDIVCounter+"]/td[2]")).getText();
ExcelUtils.setCellData(destinationCell, i, 3);
System.out.println("\n**DEBUG: Destination Cell value ="+destinationCell);
//Get Attribute
//--STD
STDCell=driver.findElement(By.xpath(DELIVER_TO_STRING+"["+xPathDIVCounter+"]/th[1]")).getText();
ExcelUtils.setCellData(STDCell, i, 4);
System.out.println("\n**DEBUG: STD Cell value ="+STDCell);
//Get Attribute
//--EXP
EXPCell=driver.findElement(By.xpath(DELIVER_TO_STRING+"["+xPathDIVCounter+"]/th[2]")).getText();
ExcelUtils.setCellData(EXPCell, i, 5);
System.out.println("\n**DEBUG: EXP Cell value ="+EXPCell);
//Get Attribute
//--STA ** SPECIAL CASE** TO DO
// EXPCell=driver.findElement(By.xpath(DELIVER_TO_STRING+"["+xPathCounter+"]/th[3]")).getText();
// ExcelUtils.setCellData(STDCell, i, 6);
}//end for
// tallyTableRowsWithNumberOfDestinations(attriAndDestinations.length);
}//end if
}//end for
driver.close(); // close the poped-up report window
driver.switchTo().window(mainWinHande);
}
private void tallyTableRowsWithNumberOfDestinations(int destinationSize){
int rowCount= driver.findElements(By.xpath(DELIVER_TO_STRING)).size();
System.out.println("\n** Table row Count: "+rowCount +"| destinations ArraySize: "+destinationSize);
try {
softAssert.assertEquals(rowCount-1, destinationSize+1, "Table rowcount didn't match with the Number of destinations selected");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void concludeAsserts(){
softAssert.assertAll();
}
}
As mentioned in the comments, you should separate your test logic out of your page objects. The page objects should report or alter the current state of the page, and it's up to the tests to decide whether what the page object reports is correct.
Break your page object method up more so that each one sets or checks one item on the page, then check each of those items from your test...
Assert.AreEqual(thePage.getOrderTotal(), expectedValue1);
Assert.AreEqual(thePage.getOrderItem(1), expectedValue2);
Assert.AreEqual(thePage.getOrderItem(2), expectedValue3);
Assert.AreEqual(thePage.getAnotherThing(), expectedValue4;
...
If you find yourself doing these things over and over again in each test, you may find it useful to bunch these asserts together into a helper method in your test class, which I suspect might be the intended purpose of verifyOrderSummary()

Problems with some Automation Testing using Before / After / Test

Problems with some Automation Testing using Before / After / Test
I'm getting stuck at the browser window, no test is executed...
Not sure why this doesn't work. I've exported some tests from Selenium IDE, exported as Java, edited that stuff in Eclipse, yet still it doesn't work...
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Checkimage {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testCheckimage() throws Exception {
driver.get("http://");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.linkText("sign in / up"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("login-email")).clear();
driver.findElement(By.id("login-email")).sendKeys("michael.sinitsin#avid.com");
driver.findElement(By.id("login-password")).clear();
driver.findElement(By.id("login-password")).sendKeys("mike1780");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if ("sign in".equals(driver.findElement(By.id("login-buttons-password")).getText())) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("login-buttons-password")).click();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if ("Tester".equals(driver.findElement(By.linkText("Tester")).getText())) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.linkText("Tester")).click();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.id("inputScoreUrl"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("inputScoreUrl")).sendKeys("http://www.sheetmusicdirect.com/scorches/smd_000001.sco");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if ("Enter a URL to a publicly accessible SCO file. No need to URL encode it, just copy and paste it in.".equals(driver.findElement(By.cssSelector("p.help-block")).getText())) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("submitScoreView")).click();
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.cssSelector("img"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
try {
assertTrue(isElementPresent(By.cssSelector("img")));
} catch (Error e) {
verificationErrors.append(e.toString());
}
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
Not sure why this doesn't work. I've exported some tests from Selenium IDE, exported as Java, edited that stuff in Eclipse, yet still it doesn't work...
Dear Michael Sinitsin,
As I see it you have here several issues:
You do not supply a valid URL to the web driver
replace driver.get("http://"); with a valid URL like driver.get("http://www.google.com");
You are exposing your user/password on a public site
Michael Sinitsin,
you should first mention proper URl driver.get("http://"); And your script is too complex,you could write it in a simplest way.