以下是firefox中的以下工作正常,而不是在硒中使用铬?

时间:2016-04-12 09:50:13

标签: selenium

火狐:      包com.webdriver;         import java.util.concurrent.TimeUnit;         import org.openqa.selenium.By;         import org.openqa.selenium.Keys;         import org.openqa.selenium.WebDriver;         import org.openqa.selenium.firefox.FirefoxDriver;

package com.webdriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Openclosegmail {

    public static void main(String[] a) throws InterruptedException {
        // Initialize driver  
        System.setProperty("webdriver.chrome.driver", "C:\\Mine New\\1EclipseWorkPath1\\Sprint 10\\src\\chromedriver.exe");
        WebDriver dr = new ChromeDriver();
        //Maximize browser window   
        dr.manage().window().maximize();
        //Go to URL  
        dr.get("https://www.google.com");
        //Set  timeout  

        // Open new tab  
dr.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
        //Go to URL  
        dr.get("https://www.gmail.com");
        //Set new tab timeout  

        // Do some operation          
        //dr.findElement(By.id("signIn")).click();
        dr.findElement(By.id("Email")).sendKeys("abdulazeem5513");
        dr.findElement(By.id("next")).click();
        dr.findElement(By.id("Passwd")).sendKeys("azeem_#5513");
        dr.findElement(By.id("signIn")).click();
        dr.findElement(By.xpath("//span[@class='gb_1a gbii']")).click();
        dr.findElement(By.xpath("//a[@id='gb_71']")).click();
        Thread.sleep(2000);

        // Close new tab  
dr.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "w");

        // Switch first tab  
        dr.switchTo().defaultContent();
        Thread.sleep(2000);
        // Write search String  
        dr.findElement(By.id("lst-ib")).sendKeys("welcome to salesforce");
        // Click on Search button          
       dr.findElement(By.xpath("//button[@class='lsb']")).click();
        Thread.sleep(2000);

        // Browser close    
        dr.close();
    }

}

铬:

{{1}}

1 个答案:

答案 0 :(得分:0)

打开新标签后,您可以尝试使用切换标签吗?
您可以使用driver.switchTo().window(windowHandler);

切换标签页