如何使用Actions类在Chrome中打开新标签页 [英] How do I open a new tab in chrome using the Actions class

查看:212
本文介绍了如何使用Actions类在Chrome中打开新标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Chrome上打开新的标签页.我需要从中获取一些数据,返回到上一个选项卡并输入数据.我知道如何遍历选项卡,但无法打开新的选项卡.

How do I open a new tab on chrome. I need get some data from it, get back to my previous tab and input the data. I know how to iterate through the tabs, but I am not able to open a new tab.

硒版本:3.5.2
Chrome版本:60

Selenium version : 3.5.2
Chrome version : 60

package Amazon;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class VerifyAmazonSignInPage {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver", "C://Selenium jars/chromedriver.exe");

        WebDriver driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get("http://www.amazon.in");
        driver.findElement(By.xpath("//span[text()='Hello. Sign in']")).click();
        driver.findElement(By.id("ap_email")).sendKeys("seleniumoar1234@gmail.com");
        driver.findElement(By.id("ap_password")).sendKeys("*****");
        driver.findElement(By.id("signInSubmit")).click();
        Actions act = new Actions(driver);
        act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform();
        driver.get("http://www.gmail.com");


    }

}

推荐答案

Action类是Selenium类,只能用于自动化基于Web的应用程序.打开新标签页是在Web浏览器上执行的操作,该浏览器是一个独立的应用程序.可以通过使用java.awt包中的Robot类来完成此操作.

Action class is a selenium class which can only be used to automate webbased applications. Opening a new tab is an action performed on the webbrowser, which is a stand alone application. It can be done by using the Robot class from the java.awt package.

这篇关于如何使用Actions类在Chrome中打开新标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆