Java 登录后切换到已加载页面

Java 登录后切换到已加载页面,java,junit,cucumber,gherkin,Java,Junit,Cucumber,Gherkin,任何人都愿意帮助我在cucumber上的另一个场景中切换到新页面,因为我无法单击新页面上加载的链接,因为编译器抱怨无法定位元素。很抱歉,没有在这里发布代码,只是它是为一个企业发布的 现在进入新页面功能 @Given("^user is logged into Gmail successfully$") public void userIsLoggedIntoGmailSuccessfully(){ //getting current URL driver.ge

任何人都愿意帮助我在cucumber上的另一个场景中切换到新页面,因为我无法单击新页面上加载的链接,因为编译器抱怨无法定位元素。很抱歉,没有在这里发布代码,只是它是为一个企业发布的

现在进入新页面功能

    @Given("^user is logged into Gmail successfully$") 
    public void userIsLoggedIntoGmailSuccessfully(){ 
        //getting current URL driver.get
        ("https://mail.google.com/home/"); 
    } 

    @When("^user navigates to settings link$") 
    public void userNavigatesToSettings() { 
       //this is where all hell breaks loose 
       driver.findElement(By.xpath(".//a[contains(text(),'Settings']")).click(); 
    }

问题还不清楚。若共享代码是一个问题,那个么用一个简单的例子来复制这个问题。有人能够理解并帮助您解决问题的唯一方法…
//现在在新页面功能@Given(“^user已成功登录Gmail$”)public void userIsLoggedIntoGmailSuccessfully(){//获取当前URL驱动程序。获取(“https://mail.google.com/home/“”;}@当(“^user导航到设置链接$”)public void userNavigatesToSettings(){//这是所有hell都会释放driver.findElement的地方(By.xpath(“.//a[contains(text(),'Settings']))。单击();}
我注意到驱动程序在到达最后一个方法时为null,无法锁定其中断点。如何初始化驱动程序?同时添加代码…`WebDriver driver=null;//创建一个方法void createDriver(){System.setProperty(“WebDriver.chrome.driver”,“C:\\Users\\Downloads\\chromedriver.exe”);driver=new ChromeDriver();}`在这个伪代码中,我在外部初始化了我的驱动程序,然后有一个方法将它分配给chrome驱动程序。