如何断言与其他商店的价值?

时间:2015-07-03 05:55:33

标签: selenium-webdriver webdriver

我有一个Webform,其中有链接,点击它打开另一个新窗口,我需要断言其中存在的电子邮件ID值。

Webdriver脚本:

driver.get("http://domain.com/");
    driver.findElement(By.id("UserName")).clear();
    driver.findElement(By.id("UserName")).sendKeys("username");
    driver.findElement(By.id("Password")).clear();
    driver.findElement(By.id("Password")).sendKeys("password");
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
    driver.get("http://domain.com/AffiliateAdmin/Home");
    driver.findElement(By.id("Email")).clear();
    driver.findElement(By.id("Email")).sendKeys(em);//em store email id value , which is random generated for new account creation.
    driver.findElement(By.xpath("//input[@value='submit']")).click();
    assertEquals(em, driver.findElement(By.xpath("/x:table/x:tbody/x:tr/x:td/x:table/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr[11]/x:td[2]/x:a")).getText());
    System.out.println("Test Case Passed");

请帮助我了解相同

脚本对我来说最有价值

谢谢

1 个答案:

答案 0 :(得分:1)

        String mainwindow = driver.getWindowHandle();        

        // click on the Update btn (use XPATH or CssSelector)
        driver.findElement(By.CssSelector("a[onclick^='window.open(\'/AffiliateAdmin/Update-Affiliate?Email']")).click(); //click to brings out the new window

        Set<String> s = driver.getWindowHandles(); 
        Iterator<String> ite = s.iterator(); 
        while(ite.hasNext()) 
        { 
            String popup = ite.next(); 
            if(!popup.equalsIgnoreCase(mainwindow)){ 
                driver.switchTo().window(popup); 
                break;
              }
        }

       // do Assert here