概述
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;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.AWTException;
public class Tabs {
WebDriver driver;
Robot rb;
@BeforeTest
public void setup() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\Users\Anuja.AnujaPC\Downloads\chromedriver_win32\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://qaautomated.com");
}
@Test
public void openTab() {
//Open tab 2 using CTRL + t keys.
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
//Open URL In 2nd tab.
driver.get("http://www.qaautomated.com/p/contact.html");
//Call switchToTab() method to switch to 1st tab
switchToTab();
//perform required actions on tab 1.
driver.findElement(By.xpath("//input[@id='6']")).click();
driver.findElement(By.xpath("//input[@id='plus']"));
driver.findElement(By.xpath("//input[@id='3']"));
driver.findElement(By.xpath("//input[@id='equals']"));
//Call switchToTab() method to switch to 2nd tab.
switchToTab();
//Call switchToTab() method to switch to 1st tab
switchToTab();
}
public void switchToTab() {
//Switching between tabs using CTRL + tab keys.
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
//Switch to current selected tab's content.
driver.switchTo().defaultContent();
}
@AfterTest
public void closeTabs() throws AWTException {
//Used Robot class to perform ALT + SPACE + 'c' keypress event.
rb =new Robot();
rb.keyPress(KeyEvent.VK_ALT);
rb.keyPress(KeyEvent.VK_SPACE);
rb.keyPress(KeyEvent.VK_C);
} }此示例取自THIS BLOG POST
最后
以上就是闪闪日记本为你收集整理的webdriver java a标签_如何使用Selenium WebDriver打开新标签页并启动链接?的全部内容,希望文章能够帮你解决webdriver java a标签_如何使用Selenium WebDriver打开新标签页并启动链接?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复