英文:
Switching between browsers using Linktext in Selenium
问题
这是如何在Selenium中使用linkText
切换浏览器页面的方式:
答案1
得分: 1
public class locatorsPractice {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver","/path");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.navigate().to("https://browser url");
String strMainWindowHandle = driver.getWindowHandle();
System.out.println("Window title" + driver.getTitle());
driver.findElement(By.linkText("Google")).click();
Set<String> strHandles = driver.getWindowHandles();
for (String handle : strHandles) {
driver.switchTo().window(handle);
String strTitle = driver.getTitle();
if (strTitle.equalsIgnoreCase("Google")) {
System.out.println(driver.getTitle());
driver.manage().window().maximize();
Thread.sleep(2000);
driver.close();
}
}
}
}
英文:
public class locatorsPractice {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver","/path");
WebDriver driver =new FirefoxDriver();
driver.manage().window().maximize();
driver.navigate().to("https://browser url");
String strMainWindowHandle=driver.getWindowHandle();
System.out.println("Window title"+driver.getTitle());
driver.findElement(By.linkText("Google")).click();
Set <String> strHandles=driver.getWindowHandles();
for (String handle:strHandles) {
driver.switchTo().window(handle);
String strTitle=driver.getTitle();
if(strTitle.equalsIgnoreCase("Google")) {
System.out.println(driver.getTitle());
driver.manage().window().maximize();
Thread.sleep(2000);
driver.close();
}
}
}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论