【发布时间】:2017-07-18 02:20:04
【问题描述】:
在 Eclipse 中,我打算自动执行以下步骤 (1) 打开谷歌浏览器 (2) 输入https://www.flipkart.com/ (3) 最大化窗口 (4)(几秒钟后),网站显示一个新的登录窗口。 (5) 只需使用右上角的“X”图标关闭弹出窗口即可。
在代码中将警报窗口命名为尖锐,但
关于代码 Alert Sharp = Flip.switchTo().alert();收到警告信息为“未使用局部变量Sharp的值”
在执行时,不执行第 4 步和第 5 步。已经使用了 Sharp.dismiss();也使用过,但仍然没有失败。
为此编写了以下代码。请澄清
package basic;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.Alert;
public class FlipKart{
public static void main(String[]args) throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\hp\\workspace\\Selenium\\browser\\chromedriver.exe");
WebDriver Flip = new ChromeDriver();
Flip.get("https://www.flipkart.com/");
Flip.manage().window().maximize();
Thread.sleep(5000); //FLIPKART CODE
Alert Sharp = Flip.switchTo().alert();// pop -up window shown
//点击右上角的X图标关闭窗口。
Flip.findElement(By.xpath("/html/body/div[2]/div/div/button")).click();
}
}
【问题讨论】:
标签: eclipse selenium webdriver